Coder Social home page Coder Social logo

Comments (2)

Grt1228 avatar Grt1228 commented on August 17, 2024

前端保存message的上下文,发送message list到后端(需要控制字符数量,太久远的对话上下文可以舍弃掉)。详细的可以看下官方文档。
role是有三种角色的 :

    @Getter
    @AllArgsConstructor
    public enum Role {

        SYSTEM("system"),
        USER("user"),
        ASSISTANT("assistant"),
        ;
        private String name;
    }

user简单理解为问题
assistant是chatgpt的回答
通过构造message list实现上下文对话

from chatgpt-java.

Grt1228 avatar Grt1228 commented on August 17, 2024
"messages": [
		{
			"role": "user",
			"content": "你好啊我的伙伴!帮我吧下面的文字翻译成英文:我爱你**。"
		},
				{
			"role": "assistant",
			"content": "I love you china。"
		},
				{
			"role": "user",
			"content": "再翻译成中文"
		},
				{
			"role": "assistant",
			"content": "我爱你**。"
		},
				{
			"role": "user",
			"content": "下面这句话:Java是最好的开发语言"
		}
	]

流式输出返回的信息需要记录下来,组合成上面的对话形式。发送到服务端即可。
有一个需要注意的是当stream是true时,返回信息是delta,不再是message

"choices": [
		{
			"delta": {
				"content": "Java"
			},
			"index": 0,
			"finishReason": null
		}
	]

@chengpengvb

from chatgpt-java.

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.