PawinC commited on
Commit
8b750c3
1 Parent(s): 0c228e3

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +9 -4
app/main.py CHANGED
@@ -11,13 +11,13 @@ from enum import Enum
11
  from typing import Optional
12
 
13
  print("Loading model...")
14
- SAllm = Llama(model_path="/models/final-gemma2b_SA-Q8_0.gguf")#,
15
  # n_gpu_layers=28, # Uncomment to use GPU acceleration
16
  # seed=1337, # Uncomment to set a specific seed
17
  # n_ctx=2048, # Uncomment to increase the context window
18
  #)
19
 
20
- # FIllm = Llama(model_path="/models/final-gemma2b_FI-Q8_0.gguf")
21
 
22
  # def ask(question, max_new_tokens=200):
23
  # output = llm(
@@ -32,6 +32,11 @@ SAllm = Llama(model_path="/models/final-gemma2b_SA-Q8_0.gguf")#,
32
  def extract_restext(response):
33
  return response['choices'][0]['text'].strip()
34
 
 
 
 
 
 
35
  def check_sentiment(text):
36
  prompt = f'Analyze the sentiment of the tweet enclosed in square brackets, determine if it is positive or negative, and return the answer as the corresponding sentiment label "positive" or "negative" [{text}] ='
37
  response = SAllm(prompt, max_tokens=3, stop=["\n"], echo=False, temperature=0.5)
@@ -47,6 +52,7 @@ def check_sentiment(text):
47
 
48
  print("Testing model...")
49
  assert "positive" in check_sentiment("ดอกไม้ร้านนี้สวยจัง")
 
50
  print("Ready.")
51
 
52
  app = FastAPI(
@@ -117,8 +123,7 @@ def ask_gemmaFinanceTH(
117
  if prompt:
118
  try:
119
  print(f'Asking FI with the question "{prompt}"')
120
- prompt = f"""###User: {prompt}\n###Assistant:"""
121
- result = extract_restext(FIllm(prompt, max_tokens=max_new_tokens, temperature=temperature, stop=["###User:", "###Assistant:"], echo=False))
122
  print(f"Result: {result}")
123
  return FI_Response(answer=result, question=prompt, config={"temperature": temperature, "max_new_tokens": max_new_tokens})
124
  except Exception as e:
 
11
  from typing import Optional
12
 
13
  print("Loading model...")
14
+ SAllm = Llama(model_path="/models/final-gemma2b_SA-Q8_0.gguf", mmap=False, mlock=True)
15
  # n_gpu_layers=28, # Uncomment to use GPU acceleration
16
  # seed=1337, # Uncomment to set a specific seed
17
  # n_ctx=2048, # Uncomment to increase the context window
18
  #)
19
 
20
+ FIllm = Llama(model_path="/models/final-gemma7b_FI-Q8_0.gguf", mmap=False, mlock=True)
21
 
22
  # def ask(question, max_new_tokens=200):
23
  # output = llm(
 
32
  def extract_restext(response):
33
  return response['choices'][0]['text'].strip()
34
 
35
+ def ask_fi(question, max_new_tokens=200, temperature=0.5):
36
+ prompt = f"""###User: {question}\n###Assistant:"""
37
+ result = extract_restext(FIllm(prompt, max_tokens=max_new_tokens, temperature=temperature, stop=["###User:", "###Assistant:"], echo=False))
38
+ return result
39
+
40
  def check_sentiment(text):
41
  prompt = f'Analyze the sentiment of the tweet enclosed in square brackets, determine if it is positive or negative, and return the answer as the corresponding sentiment label "positive" or "negative" [{text}] ='
42
  response = SAllm(prompt, max_tokens=3, stop=["\n"], echo=False, temperature=0.5)
 
52
 
53
  print("Testing model...")
54
  assert "positive" in check_sentiment("ดอกไม้ร้านนี้สวยจัง")
55
+ assert ask_fi("Hello!, How are you today?")
56
  print("Ready.")
57
 
58
  app = FastAPI(
 
123
  if prompt:
124
  try:
125
  print(f'Asking FI with the question "{prompt}"')
126
+ result = ask_fi(prompt, max_new_tokens=max_new_tokens, temperature=temperature)
 
127
  print(f"Result: {result}")
128
  return FI_Response(answer=result, question=prompt, config={"temperature": temperature, "max_new_tokens": max_new_tokens})
129
  except Exception as e: