How Should I Add A Question To Replit ModelFarm Chat?

Question:
I’m making a chat using Replit ModelFarm, but I want to take input from the user and make the AI define it, while still having access to previous messages. How would I do so?
This is my chat so far:

model = ChatModel("chat-bison")
chat = model.chat([
  ChatSession(
    context="You are very nice.",
    examples=[
      ChatExample(
        input=ChatMessage(content=" "),
        output=ChatMessage(content=" ")
      )
    ],
    messages=[
      ChatMessage(author="USER", content="hi"),
    ],
  )
], temperature=0.2, max_output_tokens=2048)
1 Like

keep a list of chat history that you append to and pass that into messages

model = ChatModel("chat-bison")

messages = []

while 1:
    messages.append(ChatMessage(author="USER", content=input("USER: ")))
    response = model.chat(prompts=[
        ChatSession(
            context="You are very nice.",
            examples=[]],
            messages=messages
        )
    ], temperature=0.2, max_output_tokens=2048).responses[0]
    messages.append(ChatMessage(content=response.candidates[0].message))
    
    print(f"\nBOT:{messages[-1].content}\n")

https://replit.com/@QwertyQwerty88/ModelFarm-AI-Chatbot

2 Likes

@QwertyQwerty88 But wouldn’t this mean regenerated the answer to each question every time a new question is asked?

1 Like

No. That is just to give it some context of previous questions you asked and previous answers it gave.

image

@QwertyQwerty88 I’m new to ModelFarm, so there is probably something pretty simple wrong in my code, but here it is:

while True:
    messages.append(ChatMessage(author="USER", content=input("USER: ")))
    response = ChatSession(
      context="You are nice.",
      examples=[
        ChatExample(
          input=ChatMessage(content=" "),
          output=ChatMessage(content=" ")
        )
      ],
      messages=messages,
      temperature=0.2,
      max_output_tokens=2048).responses[0]
    messages.append(ChatMessage(content=response.candidates[0].message))

    print(f"\nBOT:{messages[-1].content}\n")

What’s not working? Is there an error?


@QwertyQwerty88 That is the error.

Ah I see, you set the whole thing to a ChatSession when it needs to be model.chat:

Fixed that. Now there is this error:

messages.append(ChatMessage(content=str(response.candidates[0].message)))?

Fixed that bug, now it shows this:

for the first bit, Idek that’s weird, and for the internal server error, it’s a bug, you can just create a new Repl (not fork) and copy paste the code, but may need to try that a few cause it kinda randomly effects Repls

@QwertyQwerty88 I’ve done it 4 times and still not working.

I think you made an error:

examples=[]]
           ^
           |

:person_shrugging:

Yeah. I fixed it in my program, anyways.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.