niting089 commited on
Commit
f1ce08d
1 Parent(s): ad7181c

Adding Application Files

Browse files
Files changed (4) hide show
  1. Dockerfile +11 -0
  2. app.py +75 -0
  3. chainlit.md +2 -0
  4. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+ RUN useradd -m -u 1000 user
3
+ USER user
4
+ ENV HOME=/home/user \
5
+ PATH=/home/user/.local/bin:$PATH
6
+ WORKDIR $HOME/app
7
+ COPY --chown=user . $HOME/app
8
+ COPY ./requirements.txt ~/app/requirements.txt
9
+ RUN pip install -r requirements.txt
10
+ COPY . .
11
+ CMD ["chainlit", "run", "app.py", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # OpenAI Chat completion
2
+ import os
3
+ import openai
4
+ import chainlit as cl
5
+ from chainlit.prompt import Prompt, PromptMessage
6
+ from chainlit.playground.providers import ChatOpenAI
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ # ChatOpenAI Templates
12
+ system_template = """You are a highly analytical assistant who has in-depth knowledge of science!
13
+ """
14
+
15
+ user_template = """{input}
16
+ Think through your response step by step.
17
+ Be concise in your responses
18
+ Do not make up stuff. If you don't know something, let the user know.
19
+ """
20
+
21
+ @cl.on_chat_start
22
+ async def start_chat():
23
+ settings = {
24
+ "model": "gpt-3.5-turbo",
25
+ "temperature": 0.7, # Adjust to a valid range
26
+ "max_tokens": 500,
27
+ "top_p": 1,
28
+ "frequency_penalty": 0,
29
+ "presence_penalty": 0,
30
+ }
31
+ cl.user_session.set("settings", settings)
32
+
33
+ @cl.on_message
34
+ async def main(message: cl.Message):
35
+ settings = cl.user_session.get("settings")
36
+
37
+ # Set up the OpenAI client with the API key
38
+ openai.api_key = os.getenv("OPENAI_API_KEY")
39
+
40
+ prompt = Prompt(
41
+ provider=ChatOpenAI.id,
42
+ messages=[
43
+ PromptMessage(
44
+ role="system",
45
+ template=system_template,
46
+ formatted=system_template,
47
+ ),
48
+ PromptMessage(
49
+ role="user",
50
+ template=user_template,
51
+ formatted=user_template.format(input=message.content),
52
+ ),
53
+ ],
54
+ inputs={"input": message.content},
55
+ settings=settings,
56
+ )
57
+
58
+ msg = cl.Message(content="")
59
+
60
+ # Call OpenAI and stream response
61
+ async for stream_resp in await openai.ChatCompletion.acreate(
62
+ model=settings['model'],
63
+ messages=[m.to_openai() for m in prompt.messages],
64
+ stream=True,
65
+ **settings
66
+ ):
67
+ token = stream_resp.choices[0].delta.get("content", "")
68
+ await msg.stream_token(token)
69
+
70
+ # Update the prompt object with the completion
71
+ prompt.completion = msg.content
72
+ msg.prompt = prompt
73
+
74
+ # Send and close the message stream
75
+ await msg.send()
chainlit.md ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #ScienceGPT
2
+ I am your ScienceGPT
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ chainlit==0.7.700
2
+ cohere==4.37
3
+ openai==1.3.5
4
+ tiktoken==0.5.1
5
+ python-dotenv==1.0.0