codermate commited on
Commit
34176df
1 Parent(s): 55babad
Files changed (2) hide show
  1. __pycache__/main.cpython-310.pyc +0 -0
  2. main.py +25 -6
__pycache__/main.cpython-310.pyc CHANGED
Binary files a/__pycache__/main.cpython-310.pyc and b/__pycache__/main.cpython-310.pyc differ
 
main.py CHANGED
@@ -8,10 +8,10 @@ class Message(BaseModel):
8
  role: str
9
  content: str
10
 
11
- history = [
12
  {
13
- "role": "assistant",
14
- "content": "You are a helpful assistant called Awerbot. You will help visitors of a website with their inquiries, Awersoft is a Software Development company, to contact to Awersoft the visitors should use contact@awersoft.com",
15
  }]
16
 
17
 
@@ -19,15 +19,34 @@ app = FastAPI()
19
 
20
  @app.post('/chat')
21
  async def chat(messages: list[Message]):
 
 
 
 
22
 
23
  for message in messages:
24
- history.append({'role':'user', 'content':message.content})
25
 
26
  output = client.chat_completion(
27
  model="meta-llama/Meta-Llama-3-8B-Instruct",
28
- messages=history,
29
  max_tokens=100,
30
  stop="assistant"
31
  )
32
 
33
- return output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  role: str
9
  content: str
10
 
11
+ system = [
12
  {
13
+ "role": "system",
14
+ "content": "You are a helpful assistant called Awerbot. Never say your are an assistant. You will help visitors of a website with their inquiries, Awersoft is a Software Development company, to contact to Awersoft the visitors should use contact@awersoft.com. You must generate responses shorter than 100 characters",
15
  }]
16
 
17
 
 
19
 
20
  @app.post('/chat')
21
  async def chat(messages: list[Message]):
22
+ inputs = [{
23
+ "role": "system",
24
+ "content": "You are a helpful assistant called Awerbot. Never say your are an assistant. You will help visitors of a website with their inquiries, Awersoft is a Software Development company, to contact to Awersoft the visitors should use contact@awersoft.com",
25
+ }]
26
 
27
  for message in messages:
28
+ inputs.append({'role':message.role, 'content':message.content})
29
 
30
  output = client.chat_completion(
31
  model="meta-llama/Meta-Llama-3-8B-Instruct",
32
+ messages=inputs,
33
  max_tokens=100,
34
  stop="assistant"
35
  )
36
 
37
+ output_message = output["choices"][0]["message"]
38
+ # Split the content into words
39
+ words = output_message["content"].split()
40
+
41
+ # Check if the last word contains "assistant" and remove it if it does
42
+ last_word = words[-1]
43
+ if last_word.endswith("assistant"):
44
+ words[-1] = last_word[:-len("assistant")] # Remove "assistant" from the last word
45
+
46
+ # Join the words back together to form the updated content
47
+ updated_content = ' '.join(words)
48
+
49
+ # Update the content in the output message
50
+ output_message["content"] = updated_content
51
+
52
+ return output_message