David Chu commited on
Commit
a55a212
·
unverified ·
1 Parent(s): 00d1644

refactor: new module for pydantic models

Browse files
Files changed (2) hide show
  1. app/main.py +2 -18
  2. app/models.py +27 -0
app/main.py CHANGED
@@ -1,34 +1,18 @@
1
  from fastapi import FastAPI
2
  from google import genai
3
- from pydantic import BaseModel
4
 
5
- from app import agent, config
6
 
7
  gemini = genai.Client(api_key=config.settings.google_api_key)
8
  app = FastAPI()
9
 
10
 
11
-
12
- class Source(BaseModel):
13
- title: str
14
- url: str
15
-
16
-
17
- class Statement(BaseModel):
18
- text: str
19
- sources: list[Source] | None = None
20
-
21
-
22
- class Statements(BaseModel):
23
- statements: list[Statement]
24
-
25
-
26
  @app.get("/health")
27
  def health_check():
28
  return "ok"
29
 
30
 
31
- @app.get("/ask", response_model=Statements)
32
  def ask(query: str):
33
  output = agent.respond(gemini, query)
34
  return {"statements": output}
 
1
  from fastapi import FastAPI
2
  from google import genai
 
3
 
4
+ from app import agent, config, models
5
 
6
  gemini = genai.Client(api_key=config.settings.google_api_key)
7
  app = FastAPI()
8
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  @app.get("/health")
11
  def health_check():
12
  return "ok"
13
 
14
 
15
+ @app.get("/ask", response_model=models.Statements)
16
  def ask(query: str):
17
  output = agent.respond(gemini, query)
18
  return {"statements": output}
app/models.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel, computed_field
2
+
3
+
4
+ class Source(BaseModel):
5
+ title: str
6
+ url: str
7
+ summary: str | None = None
8
+ abstract: str | None = None
9
+ doi: str | None = None
10
+ venue: str | None = None
11
+ year: int | None = None
12
+ citations: int | None = None
13
+ influential_citations: int | None = None
14
+
15
+ @computed_field
16
+ @property
17
+ def citation(self) -> str:
18
+ return f"[{self.title}]({self.url}). *{self.venue}* {self.year}."
19
+
20
+
21
+ class Statement(BaseModel):
22
+ text: str
23
+ sources: list[Source] | None = None
24
+
25
+
26
+ class Statements(BaseModel):
27
+ statements: list[Statement]