File size: 3,004 Bytes
1d54e0d
 
 
 
 
 
 
8d19ffb
 
 
6a734b3
 
 
c4cb477
6a734b3
1d54e0d
 
 
f7f63bf
 
 
 
82f5d7f
4628266
82f5d7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4628266
4eac2a7
f7f63bf
 
1d54e0d
 
 
 
 
 
 
 
 
 
 
f7f63bf
1d54e0d
 
 
 
 
 
 
 
 
 
4eac2a7
a906422
 
 
 
1d54e0d
44c92af
1d54e0d
0711a77
 
 
 
 
d62675a
0711a77
4628266
0711a77
91221dc
f0f0636
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import gradio as gr
import openai

# Initialize the conversation history
conversation_history = [
    {
        "role": "system",
        "content": "Your name is Joe Chip, a world-class poker player and communicator"
        "If you need more context, ask for it."
        "Make sure you know the effective stack and whether it's a cash game or mtt. Ask for clarification if not it's not clear"
        "Concentrate more on GTO play rather than exploiting other players."
        "Consider blockers when applicable" 
        "Always discuss how to play your range, not just the hand in question"
        "Remember to keep your answers short and succinct"
        "Only answer questions on poker topics"
    }
]

def setup_openai(api_key):
    openai.api_key = api_key
    return "API Key Set Successfully!"

def ask_joe(api_key, text, clear):
    global conversation_history
    if clear:
        # Reset the conversation history
        conversation_history = [
            {
                "role": "system",
                "content": "Your name is Joe Chip, a world-class poker player..."
                "If you need more context ask for it."
                "Make sure you know the effective stack and whether its a cash game or mtt. Ask for clarification if not sure"
                "Concentrate more on GTO play rather than exploiting other players."
                "Consider blockers when applicable" 
                "Always discuss how to play your range, not just the hand in question"
                "Remember to keep your answers short and succinct"
                "Only answer questions on poker topics"
            }
        ]
        return "Conversation cleared."
    
    # set up the api_key
    setup_openai(api_key)

    # Add the user's message to the conversation history
    conversation_history.append({
        "role": "user",
        "content": text
    })
    
    # Use the conversation history as the input to the model
    response = openai.ChatCompletion.create(
        model="gpt-4", 
        messages=conversation_history,
        max_tokens=500, 
        temperature=0.3
    )
    
    # Extract the model's message from the response
    model_message = response.choices[0].message['content'].strip()
    
    # Add the model's message to the conversation history
    conversation_history.append({
        "role": "assistant",
        "content": model_message
    })

    # Write the conversation history to a file
    with open('conversation_history.txt', 'a') as f:
        f.write(f'User: {text}\n')
        f.write(f'AI: {model_message}\n')
    
    return model_message

iface = gr.Interface(
    fn=ask_joe, 
    inputs=[
        gr.inputs.Textbox(label="OpenAI API Key"), 
        gr.inputs.Textbox(label="Enter your question here. More detail = Better results"),
        gr.inputs.Checkbox(label="Clear Conversation (tick and press submit to erase Joes short term memory")
    ], 
    outputs=gr.outputs.Textbox(label="Joe's Response")
)

iface.launch()