-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
42 lines (33 loc) · 2 KB
/
server.py
File metadata and controls
42 lines (33 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import requests
import markdown
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.middleware.cors import CORSMiddleware
import google.generativeai as genai
import dotenv
import os
dotenv.load_dotenv()
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
def return_prompt(bcv):
return f"I want you to act as an bible scholar. I will give you a Bible passage - book, chapter, and one or more verses - and you will respond with the following information: book, chapter, verse(s), content of the verse(s) in a single text paragraph (using the New American Standard Translation 1995), name of author/writer, year when the passage was written (indicate whether the time is certain or approximate (and how confident the approximation is)), a brief (10-20 word) description of the pericope or context of the passage (for a pericope, identify the verse numbers that make up the pericope), up to3 main theme(s) (as a numbered list), and up to 5 related verses (as a numbered list) - either quotations, allusions, or possible allusions (indicating the type of relationship per item). Do not include an intro sentence, bold all section names, and do not ask if there are any other questions. Response should be in clean markdown format. The passage is {bcv}"
@app.get("/ol/{bcv}")
def read_root(bcv):
url = "http://localhost:11434/api/generate"
data = { "model": "gemma3:12b", "prompt": return_prompt(bcv), "stream": False }
response = requests.post(url, json=data)
return HTMLResponse(content=markdown.markdown(response.json()["response"]))
@app.get("/ggl/{bcv}")
def read_ggl(bcv):
model = genai.GenerativeModel("gemini-2.0-flash")
response = model.generate_content(return_prompt(bcv))
return HTMLResponse(content=markdown.markdown(response.text))
# return HTMLResponse(content=response.text)