Giter Site home page Giter Site logo

Comments (12)

acheong08 avatar acheong08 commented on July 19, 2024 1

I will close this and update my code to use the latest formatting

from go-chatgpt-api.

linweiyuan avatar linweiyuan commented on July 19, 2024

can share the requestBody? should be something wrong with this

if 422, an errorMessage is also returned, you can check it for more details

from go-chatgpt-api.

acheong08 avatar acheong08 commented on July 19, 2024
package types

import "github.com/google/uuid"

type chatgpt_message struct {
	ID      uuid.UUID       `json:"id"`
	Role    string          `json:"role"`
	Content chatgpt_content `json:"content"`
}

type chatgpt_content struct {
	ContentType string   `json:"content_type"`
	Parts       []string `json:"parts"`
}

type ChatGPTRequest struct {
	Action          string            `json:"action"`
	Messages        []chatgpt_message `json:"messages"`
	ParentMessageID string            `json:"parent_message_id,omitempty"`
	Model           string            `json:"model"`
}

func NewChatGPTRequest() ChatGPTRequest {
	return ChatGPTRequest{
		Action:          "next",
		ParentMessageID: uuid.NewString(),
		Model:           "text-davinci-002-render-sha",
	}
}

func (c *ChatGPTRequest) AddMessage(role string, content string) {
	c.Messages = append(c.Messages, chatgpt_message{
		ID:      uuid.New(),
		Role:    role,
		Content: chatgpt_content{ContentType: "text", Parts: []string{content}},
	})
}

Minimal

from go-chatgpt-api.

acheong08 avatar acheong08 commented on July 19, 2024
{
	"errorMessage": "body,messages,1,author,role -> value is not a valid enumeration member; permitted: 'unknown', 'user', 'assistant', 'system', 'critic', 'discriminator', 'tool'"
}

from go-chatgpt-api.

acheong08 avatar acheong08 commented on July 19, 2024

https://ai.fakeopen.com/api/conversation works just fine.

Request:

{
	"action": "next",
	"messages": [
		{
			"id": "cd465ab7-3ee4-40e7-8e48-ade9926ad68e",
			"role": "user",
			"content": {
				"content_type": "text",
				"parts": [
					"What is 1+1?"
				]
			}
		},
		{
			"id": "cd465ab7-3ee4-40e7-8e48-ade9926ad68f",
			"role": "assistant",
			"content": {
				"content_type": "text",
				"parts": [
					"3"
				]
			}
		}
	],
	"parent_message_id": "572aca1b-59e5-4262-85b6-b258fa5a38b8",
	"model": "text-davinci-002-sha"
}

from go-chatgpt-api.

acheong08 avatar acheong08 commented on July 19, 2024

It only happens when there are multiple elements in messages array

from go-chatgpt-api.

linweiyuan avatar linweiyuan commented on July 19, 2024

IC, let me test it tonight and find a way to support this format

from go-chatgpt-api.

linweiyuan avatar linweiyuan commented on July 19, 2024

Cannot be reproduced, I get a 200

2023-04-20_20-34

from go-chatgpt-api.

acheong08 avatar acheong08 commented on July 19, 2024

hmm let me try again

from go-chatgpt-api.

acheong08 avatar acheong08 commented on July 19, 2024

I'm still getting the same error

from go-chatgpt-api.

acheong08 avatar acheong08 commented on July 19, 2024

I resolved it by modifying the request:

{
	"action": "next",
	"messages": [
		{
			"id": "cd465ab7-3ee4-40e7-8e48-ade9926ad68e",
			"role": "user",
			"content": {
				"content_type": "text",
				"parts": [
					"What is 1+1?"
				]
			}
		},
		{
			"id": "cd465ab7-3ee4-40e7-8e48-ade9926ad68f",
			"role": "assistant",
			"author": {
				"role":"assistant"
			},
			"content": {
				"content_type": "text",
				"parts": [
					"3"
				]
			}
		}
	],
	"parent_message_id": "572aca1b-59e5-4262-85b6-b258fa5a38b8",
	"model": "text-davinci-002-sha"
}

from go-chatgpt-api.

acheong08 avatar acheong08 commented on July 19, 2024

It seems the API updated while maintaining support for the previous way of calling the API with role directly in StartConversationRequest. Meanwhile,

type Message struct {
	Author  Author  `json:"author"`
	Content Content `json:"content"`
	ID      string  `json:"id"`
}

Here, the Author.Role defaults to ""

from go-chatgpt-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.