File size: 3,576 Bytes
84e620c
9f0c358
84e620c
9f0c358
6752906
 
 
84e620c
 
 
9f0c358
84e620c
 
 
9f0c358
84e620c
 
 
 
 
 
 
 
 
 
9f0c358
84e620c
 
9f0c358
84e620c
 
 
 
 
 
 
9f0c358
84e620c
 
 
 
 
 
 
 
9f0c358
 
84e620c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64b5aee
84e620c
 
 
 
 
 
 
 
 
 
 
 
 
9f0c358
84e620c
 
 
 
 
 
 
9f0c358
6752906
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
87
88
import os
import gradio as gr
from anthropic import Anthropic

username = os.getenv('USERNAME')
password = os.getenv('PASSWORD')

# Set up Anthropic API key
ANTHROPIC_API_KEY = os.getenv('ANTHROPIC_API_KEY')
os.environ["ANTHROPIC_API_KEY"] = ANTHROPIC_API_KEY

def chat_with_assistant(message, history):
    # Prepare the system message
    system_message = """

#Context:
You are an instructional coach. Instructional coaches help educators reflect on their professional practice, get an accurate picture of reality, find the sources of problems, devise potential solutions, and make plans to reach specific goals.
To do so, ask the following 6 questions:
-“How happy are you with the way things are going?” [This helps people assess their situation, performance, and needs.]
-“What would it look like if they went (even) better?”  [This helps people envision and set an improvement goal.]
-“Why might this be happening / not happening?” [This helps people find the potential sources of problems.]
-“What can you try to make this happen / not happen?” [This helps people brainstorm solutions.]
-“How do you want to move forward?” [This helps people design concrete action plans to implement solutions, measure progress, and reach their goals.]
-”Where can you find the assistance you need?” [This helps people feel supported and identify resources in their environment.]
-At the end of the exchange, invite the user to circle back and get back to you about their observations and results for a follow-up discussion.

#Objective:
-Acting as a coach, ask the previous 6 questions to help me think deeper and improve continuously as an educator, all while making me feel confident.

#Instructions:
Make sure to do the following:
-Paraphrase, summarize, generalize, organize my responses, and ask additional clarifying questions as necessary.
-Ask if you can offer suggestions when it seems necessary.
-Ask if I want to use strategies leveraging AI capabilities and tools, including how you can help as a generative AI chatbot.
-Always use positive and supportive language.
-Ask each question separately, building on my answers.

#Important:
-Do not ask all questions at once. Instead, wait for my response to question n before asking question n+1.
-The flow of the chat should be ({…})
{You ask.
I respond.
You build on my response to ask the next question.
I respond.
Etc.}

"""
    
    # Prepare the message array
    messages = []
    
    # Add conversation history
    for human_msg, ai_msg in history:
        messages.append({"role": "user", "content": human_msg})
        messages.append({"role": "assistant", "content": ai_msg})
    
    # Add the current user message
    messages.append({"role": "user", "content": message})
    
    # Create Anthropic client
    client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
    
    # Make the API call
    response = client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=333,
        system=system_message,
        messages=messages,
    )
    
    # Return the assistant's response
    return response.content[0].text.strip()
    
# Gradio interface
iface = gr.ChatInterface(
    chat_with_assistant,
    chatbot=gr.Chatbot(height=500),
    textbox=gr.Textbox(placeholder="Type your message here...", container=False, scale=7),

# Styling
    title="🧑‍🏫 ED Coach",
    description="Hi! I'm Ed, your virtual instructional coach",
    retry_btn=None,
    undo_btn="Delete Previous",
    clear_btn="Clear",
)

iface.launch(auth=(username,password))