File size: 3,196 Bytes
9af5154
9edfb23
 
b4dbaa8
4fb8c39
9af5154
 
 
3ca6a3f
e7826a7
3ca6a3f
9af5154
 
 
e7826a7
 
9af5154
 
 
 
 
4fb8c39
9af5154
 
 
 
 
 
b4dbaa8
e7826a7
9af5154
 
e7826a7
9af5154
 
 
 
e7826a7
 
 
9af5154
 
 
 
 
 
 
e7826a7
9af5154
9edfb23
9af5154
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
from openai import OpenAI
import gradio as gr

api_key = 'sk-UazEKXLCE5Uyn5jZE068Dd87C19c44Ae912f6a55Ac1b6616'
client = OpenAI(base_url='https://api.deerapi.com/v1',api_key=api_key)

description =  """
    # GUI Prompt Debugging Interface
    
    This version **does not** save your prompt editing history,lease **manually** save all the works in a local after finishing debugging a prompt.
    
    Note: Temperature is a parameter that controls the “creativity” or randomness of the text generated. A higher temperature results in more diverse and creative output, while a lower temperature makes the output more deterministic and focused.
    """

def respond(msg, chat_history, model, system_prompt, temperature):
    history_openai_format = [{"role": "system", "content": system_prompt}]
    for human, assistant in chat_history:
        history_openai_format.append({"role": "user", "content": human })
        history_openai_format.append({"role": "assistant", "content":assistant})
    history_openai_format.append({"role": "user", "content": msg})
    completion = client.chat.completions.create(model=model, messages=history_openai_format, max_tokens=200, temperature=temperature)
    print(completion)
    yield completion.choices[0].message.content

with gr.Blocks(theme=gr.themes.Monochrome(text_size=gr.themes.sizes.text_lg)) as demo:
    gr.Markdown(description)
    with gr.Column():
        with gr.Row():
            model = gr.Radio(["gpt-3.5-turbo-1106", "gpt-4-1106-preview", "claude-3-5-sonnet-20240620", "gemini-1.5-pro-preview-0514", "glm-4-0520", "moonshot-v1-128k", "qwen-max-0428", "Baichuan2-Turbo-192k", "doubao-pro-128k", "llama2-70b-4096", "llama3-70b-8192"], label="Therapist Model", value="gpt-3.5-turbo-1106")
        with gr.Row():
            temperature = gr.Number(label="Temperature", value=0)
        with gr.Row():
            system_prompt = gr.TextArea(max_lines=4,label="System Prompt for the Therapist", value="""You are a psychotherapist who will use 'cognitive reframing' strategy to help clients reframe their negative emotions.
You should follow these three steps: 
1. At first, the client will express their negative emotion. You need to guide them to separate their situation and thoughts. 
2. Then the client will reply to you. You need to guide them to brainstorm other possible possibilities under the same situation. 
3. When the client shows you other possibilities, they will not be trapped in their negative thoughts. That is what 'cognitive reframing' means. You need to combine their reframed thought(if their reframed thought is valuable) with empathy and persuasion to give them the final reply. 
Do not say more than three sentences in one response.
Here are some background information of the patient:
Gender: Male
Age: 18
Identify as: Straight
Relationship status: Single
Religion is not important at all to the client
The client is not spiritual
The client consider therapy today because feeling depressed
The client expect a therapist who listens and assigns homework""")
        gr.ChatInterface(respond, additional_inputs=[model, system_prompt, temperature])
    
if __name__ == "__main__":
    demo.launch(show_api=False)