Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Talking to NPC after running and getting no reply #14

Open
jonny-meng opened this issue Sep 2, 2023 · 4 comments
Open

Talking to NPC after running and getting no reply #14

jonny-meng opened this issue Sep 2, 2023 · 4 comments

Comments

@jonny-meng
Copy link

Hello, when I reproduce your project, I can open the scene normally and add the preset scenes and NPCs. But when I have a conversation with the NPC, the NPC won't respond. In the logs/xxx_prompt.txt file, there is only the content sent by the system, and there is no GPT reply content, and the terminal displays such an error after a long time:

Exception in callback functools.partial(<function WebSocketProtocol._run_callback.. at 0x7efe8d7468b0>, <Task finished name='Task-16' coro=<WebSocketHandler.on_message() done, defined at /mnt/c /Users/jonny/AgentSims/main.py:23> exception=KeyError('content')>)
Traceback (most recent call last):
File "/home/jonny/.local/lib/python3.9/site-packages/tornado/ioloop.py", line 738, in _run_callback
ret = callback()
File "/home/jonny/.local/lib/python3.9/site-packages/tornado/websocket.py", line 639, in
self.stream.io_loop.add_future(result, lambda f: f.result())
File "/mnt/c/Users/jonny/AgentSims/main.py", line 24, in on_message
await self.app_cache.execute(self, message)
File "/mnt/c/Users/jonny/AgentSims/app.py", line 181, in execute
res = await cmd._execute(info)
File "/mnt/c/Users/jonny/AgentSims/command/command_base.py", line 40, in _execute
data = await self. execute(params)
File "/mnt/c/Users/jonny/AgentSims/command/chat/ChatWithNPC.py", line 43, in execute
response = result["data"]['chat']['content']
KeyError: 'content'

I would like to ask what is the problem, is there something wrong with my API Key?

@Highmiao
Copy link

Highmiao commented Sep 2, 2023

I have also encountered the same mistake as yours. I think I can provide the situation I have encountered and the solution for your reference.

I was checking the content returned by gpt and I found that my gpt returned 10 conversations in this format: {"content":"{name} : xxx"}.

But the project's code seemed to want only one such reply, so I added the prompt word, and at the end of the prompt I forced my gpt to give only one dialog, like # 5 in the example below.

.\agent\prompt\chat.txt

You must follow the following criteria:

  1. You should just tell the sentences you want to speak in the JSON format:

{"content":"{name} : xxx"}

  1. If The last content from the one you are talking to is "None" or nothing, you must start a conversation politely about the topic.

  2. If The last content from the one you are talking to is not "None" or nothing, you must respond appropriately to the other person's words.

  3. no more than 30 words.

  4. only one sentence is enough.

After making this change, my project no longer reported such errors, and it began to work normally

@py499372727 py499372727 pinned this issue Sep 3, 2023
@py499372727
Copy link
Owner

Thanks for the solution!

@ireneyunfei
Copy link

ireneyunfei commented Oct 13, 2023

@libinhang and I encountered the similar issue, some error message popped when it failed to get the text in
content = result["data"]['chat']['content']
the error is at line #129 in Tick.py

what works for us is simply ignore this by hardcoding a content:
try:
content = result["data"]['chat']['content']
except:
content = 'Sorry, i did not catch that'

Hope this helps

@2642543078
Copy link

我问与NPC交谈,这一部分代码在哪里实现的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants