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

Upload main.py

Browse files
Files changed (1) hide show
  1. app/main.py +6 -6
app/main.py CHANGED
@@ -2,10 +2,9 @@
2
  # coding: utf-8
3
  from os import listdir
4
  from os.path import isdir
5
- from fastapi import FastAPI, HTTPException, Request, responses
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from llama_cpp import Llama
8
- from fastapi import Body
9
 
10
  from pydantic import BaseModel
11
  from enum import Enum
@@ -18,7 +17,7 @@ SAllm = Llama(model_path="/models/final-gemma2b_SA-Q8_0.gguf")#,
18
  # n_ctx=2048, # Uncomment to increase the context window
19
  #)
20
 
21
- FIllm = Llama(model_path="/models/final-gemma2b_FI-Q8_0.gguf")
22
 
23
  # def ask(question, max_new_tokens=200):
24
  # output = llm(
@@ -108,8 +107,8 @@ def perform_sentiment_analysis(prompt: str = Body(..., embed=True, example="I li
108
  @app.post('/FI')
109
  def ask_gemmaFinanceTH(
110
  prompt: str = Body(..., embed=True, example="What's the best way to invest my money"),
111
- temperature: float = 0.5,
112
- max_new_tokens: int = 200
113
  ) -> FI_Response:
114
  """
115
  Ask a finetuned Gemma a finance-related question, just for fun.
@@ -118,9 +117,10 @@ def ask_gemmaFinanceTH(
118
  if prompt:
119
  try:
120
  print(f'Asking FI with the question "{prompt}"')
 
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)
124
  except Exception as e:
125
  return HTTPException(500, FI_Response(code=500, answer=str(e), question=prompt))
126
  else:
 
2
  # coding: utf-8
3
  from os import listdir
4
  from os.path import isdir
5
+ from fastapi import FastAPI, HTTPException, Request, responses, Body
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from llama_cpp import Llama
 
8
 
9
  from pydantic import BaseModel
10
  from enum import Enum
 
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(
 
107
  @app.post('/FI')
108
  def ask_gemmaFinanceTH(
109
  prompt: str = Body(..., embed=True, example="What's the best way to invest my money"),
110
+ temperature: float = Body(0.5, embed=True),
111
+ max_new_tokens: int = Body(200, embed=True)
112
  ) -> FI_Response:
113
  """
114
  Ask a finetuned Gemma a finance-related question, just for fun.
 
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:
125
  return HTTPException(500, FI_Response(code=500, answer=str(e), question=prompt))
126
  else: