kjozsa commited on
Commit
a1c827d
·
1 Parent(s): c32815c

together.ai integration

Browse files
Files changed (2) hide show
  1. chat/__init__.py +2 -2
  2. chat/togetherchat.py +34 -0
chat/__init__.py CHANGED
@@ -2,7 +2,7 @@ import re
2
 
3
  import streamlit as st
4
  from loguru import logger
5
- from .ollamachat import ask, models
6
 
7
  # from .transformerschat import ask, models
8
 
@@ -24,7 +24,7 @@ class Actor:
24
 
25
 
26
  def setup(question):
27
- pp1 = pp2 = pp3 = "Answer questions as precisely as you can! If you want to ask anyone, always start your sentence with their role. Never start your sentence with your own name. Share your inner thoughts inside parentheses. SAY ONLY ONE SINGLE SENTENCE!"
28
  priest = Actor("Priest", available_models[0], "You are the Priest. There are 3 people standing in a circle: the Priest (that's you), the Teacher and the Kid.", pp1)
29
  teacher = Actor("Teacher", available_models[0], "You are the Teacher. There are 3 people standing in a circle: the Priest, the Teacher (that's you) and the Kid.", pp2)
30
  kid = Actor("Kid", available_models[0], "You are the Kid. There are 3 people standing in a circle: the Priest, the Teacher and the Kid (that's you).", pp3)
 
2
 
3
  import streamlit as st
4
  from loguru import logger
5
+ from .togetherchat import ask, models
6
 
7
  # from .transformerschat import ask, models
8
 
 
24
 
25
 
26
  def setup(question):
27
+ pp1 = pp2 = pp3 = "Answer questions as precisely as you can! If you want to ask anyone, always start your sentence with their role. Never start your sentence with your own name. Share your inner thoughts inside parentheses. SAY ONLY ONE SINGLE SENTENCE! Do not say 'sure, here is my response' or anything such)"
28
  priest = Actor("Priest", available_models[0], "You are the Priest. There are 3 people standing in a circle: the Priest (that's you), the Teacher and the Kid.", pp1)
29
  teacher = Actor("Teacher", available_models[0], "You are the Teacher. There are 3 people standing in a circle: the Priest, the Teacher (that's you) and the Kid.", pp2)
30
  kid = Actor("Kid", available_models[0], "You are the Kid. There are 3 people standing in a circle: the Priest, the Teacher and the Kid (that's you).", pp3)
chat/togetherchat.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from loguru import logger
2
+ from openai import OpenAI
3
+ import os
4
+
5
+ TOGETHER_API_KEY = os.environ.get("TOGETHER_API_KEY")
6
+
7
+ client = OpenAI(
8
+ api_key=TOGETHER_API_KEY,
9
+ base_url='https://api.together.xyz/v1',
10
+ )
11
+
12
+
13
+ def models():
14
+ return [
15
+ 'meta-llama/Llama-2-13b-chat-hf',
16
+ 'meta-llama/Llama-2-70b-chat-hf',
17
+ 'Open-Orca/Mistral-7B-OpenOrca',
18
+ 'teknium/OpenHermes-2p5-Mistral-7B',
19
+ 'zero-one-ai/Yi-34B-Chat',
20
+ ]
21
+
22
+
23
+ def ask(model, system_prompt, pre_prompt, question):
24
+ messages = [
25
+ {'role': 'system', 'content': f"{system_prompt} {pre_prompt}", },
26
+ {'role': 'user', 'content': f"{question}", },
27
+ ]
28
+ logger.debug(f"<< {model} << {question}")
29
+
30
+ chat_completion = client.chat.completions.create(messages=messages, model=model)
31
+ response = chat_completion.choices[0]
32
+ answer = response.message.content
33
+ logger.debug(f">> {model} >> {answer}")
34
+ return answer