#OpenAI API context issues.

29 messages · Page 1 of 1 (latest)

sullen cipher
#

I'm trying to make my own discord bot (py-cord) that acts as a front-end for the OpenAI api (davinci, ada, Dalle, etc). It has gone well so far until I tried to add context so I can engage in conversation with my bot. Here's my error:
https://pastebin.com/VuWsxFuP
./Main.py:
https://pastebin.com/isVQwzgW
./Modules/Models.py:
https://pastebin.com/0bbNRqZR
./Data/Context.Json:
{
"openai_api_key": "owo",
"models": {
"davinci": "davinci",
"curie": "curie",
"babbage": "babbage"
}
}

From what I can gather the issue is line 18 of Models.py where I apply the context, but I have no idea what is wrong with it.

glass tapir
#

context=self.context

#

I don’t know python very well but I think you can try remove this line in models.py

#

there seems no such argument context

tepid crescentBOT
#

@sullen cipher

Kaplan's message blocked by AutoMod

We are committed to fostering a positive atmosphere and have implemented additional filters to block any inappropriate or disruptive language and topics.

sullen cipher
#

I've made a little bit of progress, I had chatgpt write most of this and it really messed things up

sullen cipher
#

Still trying to figure out exactly how to provide context, so far I've just appended my inputs and its responses into context.json and then pass that in as the AI's prompt

#

but it gets kinda confused and starts roleplaying or making characters

#

{"convo": "Me: Hi, what's your name?\nMe: \nYou: Hi there! My name is Bot. What's yours?\n"}

glass tapir
sullen cipher
#

wdym?

#

ohh

#

i probably need to remove the \n when I send it to the ai

glass tapir
#

I suggest add stop sequences into the request

sullen cipher
#

what are stop sequences?

glass tapir
#

stop=[“Human: “, “AI”]

#

a flag to show when to stop generating further tokes, it can also help the model understand the conversation

sullen cipher
#

oh okay

glass tapir
#

add a head

#

like this: The following is a conversation between human and ai.

#

then add your conversation below

sullen cipher
#

k

#

Yeah it's still getting confused

#
async def text(ctx, query, model):
        with open('./Data/Context.json', 'r') as f:
          context = json.load(f)
        context["convo"] += f"Me: {query}\n"
        with open('./Data/Context.json', 'w') as f:
          json.dump(context, f)
        response = openai.Completion.create(
            engine=model,
            prompt=f"The following is a conversation between me (Me), and you (You): {context['convo']}",
            max_tokens=1000,
            n=1,
            stop=["Me:"],
            temperature=0.5,
            user=f"ctx.author"
        )
        context["convo"] += f"{response.choices[0].text}\n"
        with open('./Data/Context.json', 'w') as f:
          json.dump(context, f)
        await ctx.respond(response.choices[0].text) 
#
{
  
  "convo": "Me: Hi! What's your name?\nYou: \nYou: My name is John.\nMe: Hi, What's your name?\n\nYou: My name is John.\nMe: What is your name?\n\nYou: My name is John.\n"
}```
sullen cipher
#

I figured it out