openai-java icon indicating copy to clipboard operation
openai-java copied to clipboard

How to correlate the context of a session?

Open KylinShinlyLin opened this issue 2 years ago • 9 comments

I found no input parameter for associating context.

KylinShinlyLin avatar Feb 10 '23 03:02 KylinShinlyLin

You either change the name of the model to reference the fine tuned name you added the training to or you include it in the previous answer in the prompt.

cryptoapebot avatar Feb 10 '23 03:02 cryptoapebot

请问您解决这个问题了吗?我仍然不能让上下文联系起来,并且我也尝试了提出了上下文联系的问题,但chatGPT的每次回答依然不相关联。 Have you solved the problem? I still couldn't get the context to connect, and I tried to ask the contextual question, but chatGPT's response was still irrelevant every time.

whatevertuzi avatar Feb 10 '23 08:02 whatevertuzi

prompt = “Human: XXXX Ai: Human: XXX”, 试过这种方式吗?把之前的问题或回答包含进新的prompt里

Yourwon avatar Feb 10 '23 09:02 Yourwon

谢谢,但是这样的话个人感觉过于繁琐,我在尝试其他办法

whatevertuzi avatar Feb 10 '23 09:02 whatevertuzi

我看到了其他人的讨论:https://machbbs.com/v2ex/624319

whatevertuzi avatar Feb 10 '23 09:02 whatevertuzi

How to set language of response result, I develop for Chinese, I believe most people don't need English result.

haoning7788 avatar Feb 10 '23 10:02 haoning7788

可以让用户在提问前加上“请用中文回答”,当然你也可以把这句话加在你的code。 Let the user add "Please answer in Chinese" before the question, of course you can also add this sentence to your code.

whatevertuzi avatar Feb 10 '23 12:02 whatevertuzi

Just FYI, OpenAI hasn't released the ChatGPT APIs yet, so the features in the ChatGPT beta UI they host might not be available to API builders yet. The best you can do is keep track of your own chats. OpenAI allows you to submit a .user() field, so the best way for now is to just add every interaction to a file, a simple sqlite, or a java Map.

Gson g = new Gson();
HashMap<String, EvictingQueue<String>> context = Maps.newHashMap();
String user = "person";
EvictingQueue<String> ctx = EvictingQueue.create(20);
context.put(user, ctx);

Then just add each prompt and result to the ctx by looking it up by user and rewriting it in the HashMap. You can actually store the whole object in a file too to persist it.

fianl static Type context_type = new TypeToken<HashMap<String, EvictingQueue<String>>>() {}.getType();
try {
  File file = new File(pathtofile);
  Reader reader = Files.newBufferedReader(Paths.get(pathtofile));
  context = g.fromJson(reader, context_type);

  Writer writer = Files.newBufferedWriter(Paths.get(pathtofile));
  g.toJson(context, writer);
} catch (IOException | JsonSyntaxException e) {
  e.printStackTrace();
}

Anyways, good luck. If the ChatGPT api does become available, then you can always request a feature based on how they handle it instead of keeping track of it in your client.

cryptoapebot avatar Feb 10 '23 15:02 cryptoapebot

有方法吗?

zengwp avatar Feb 16 '23 08:02 zengwp