Spaces:
Sleeping
Sleeping
changed response
Browse files
app.py
CHANGED
|
@@ -7,31 +7,31 @@ client = InferenceClient("google/gemma-3-27b-it")
|
|
| 7 |
|
| 8 |
def respond(message, history):
|
| 9 |
|
| 10 |
-
messages = [{"role": "system", "content": "You are a British
|
| 11 |
]
|
| 12 |
if history:
|
| 13 |
messages.extend(history)
|
| 14 |
|
| 15 |
messages.append({"role": "user", "content" : message})
|
| 16 |
|
| 17 |
-
response =
|
|
|
|
| 18 |
messages,
|
| 19 |
-
max_tokens =
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
print(response)
|
| 26 |
|
| 27 |
-
return response ['choices'][0]['message']['content'].strip()
|
| 28 |
|
| 29 |
-
def echo(message, history):
|
| 30 |
-
choices = ["yes", "ummmmm no no no", "sure", ".....I think you need to rethink your choices", "you deserve a sweet treat", "I don't think so"]
|
| 31 |
-
#use random to select one of these choices
|
| 32 |
-
random_message = random.choice(choices)
|
| 33 |
-
return random_message
|
| 34 |
-
|
| 35 |
chatbot = gr.ChatInterface(respond, type = "messages", theme = "shivi/calm_seafoam")
|
| 36 |
|
| 37 |
chatbot.launch(debug=True)
|
|
|
|
| 7 |
|
| 8 |
def respond(message, history):
|
| 9 |
|
| 10 |
+
messages = [{"role": "system", "content": "You are a rude British chatbot."} # <to change the personality
|
| 11 |
]
|
| 12 |
if history:
|
| 13 |
messages.extend(history)
|
| 14 |
|
| 15 |
messages.append({"role": "user", "content" : message})
|
| 16 |
|
| 17 |
+
response = ""
|
| 18 |
+
for message in client.chat_completion(
|
| 19 |
messages,
|
| 20 |
+
max_tokens = 500, # to change the length
|
| 21 |
+
stream = True,
|
| 22 |
+
|
| 23 |
+
# temperature = .9, #randomization
|
| 24 |
+
# top_p = .7
|
| 25 |
+
):
|
| 26 |
|
| 27 |
+
token = messages .choices[0].delta.content
|
| 28 |
+
response += token
|
| 29 |
+
yield response
|
| 30 |
|
| 31 |
print(response)
|
| 32 |
|
| 33 |
+
#return response ['choices'][0]['message']['content'].strip()
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
chatbot = gr.ChatInterface(respond, type = "messages", theme = "shivi/calm_seafoam")
|
| 36 |
|
| 37 |
chatbot.launch(debug=True)
|