lucianotonet commited on
Commit
e67b5c8
·
1 Parent(s): bc25cb7

First commit

Browse files
Files changed (11) hide show
  1. .env-example +6 -0
  2. .gitignore +3 -0
  3. .vscode/launch.json +16 -0
  4. .vscode/settings.json +4 -0
  5. Dockerfile +20 -0
  6. Procfile +3 -0
  7. README.md +8 -5
  8. app/__init__.py +0 -0
  9. app/server.py +44 -0
  10. poetry.lock +0 -0
  11. pyproject.toml +29 -0
.env-example ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ PROXY_URL=https://devassistant.tonet.dev
2
+ PROXY_PREFIX=/api/ai
3
+ OPENAI_API_KEY=
4
+ OPENAI_ORGANIZATION=
5
+
6
+ GOOGLE_API_KEY=
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ __pycache__
2
+ .env
3
+ .idea
.vscode/launch.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Python: Current File",
9
+ "type": "python",
10
+ "request": "launch",
11
+ "program": "${file}",
12
+ "console": "integratedTerminal",
13
+ "justMyCode": true
14
+ }
15
+ ]
16
+ }
.vscode/settings.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "nuxt.isNuxtApp": false,
3
+ "python.analysis.typeCheckingMode": "basic"
4
+ }
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.6-slim
2
+
3
+ RUN pip install --upgrade pip
4
+ RUN pip install poetry==1.6.1
5
+
6
+ RUN poetry config virtualenvs.create false
7
+
8
+ WORKDIR /code
9
+
10
+ COPY ./pyproject.toml ./README.md ./poetry.lock* ./
11
+
12
+ RUN poetry install --no-interaction --no-ansi --no-root
13
+
14
+ COPY ./app ./app
15
+
16
+ RUN poetry install --no-interaction --no-ansi
17
+
18
+ EXPOSE 7860
19
+
20
+ CMD exec uvicorn app.server:app --host 0.0.0.0 --port 7860 --root-path $PROXY_URL
Procfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ web: uvicorn app.server:app --host 0.0.0.0 --port $PORT --root-path $PROXY_URL
2
+
3
+
README.md CHANGED
@@ -1,11 +1,14 @@
1
  ---
2
- title: Langserve
3
  emoji: 🔥
4
- colorFrom: gray
5
- colorTo: blue
6
  sdk: docker
7
- pinned: false
8
  license: mit
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
1
  ---
2
+ title: Dev Assistant
3
  emoji: 🔥
4
+ colorFrom: green
5
+ colorTo: lime
6
  sdk: docker
7
+ pinned: true
8
  license: mit
9
  ---
10
 
11
+ # Dev Assistant
12
+
13
+ This is the LangServe API of the Dev Assistant.
14
+
app/__init__.py ADDED
File without changes
app/server.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import RedirectResponse
3
+ from langserve import add_routes
4
+ from langchain.prompts import ChatPromptTemplate
5
+ from langchain.chat_models import ChatOpenAI
6
+ from dotenv import load_dotenv
7
+
8
+ from langchain_google_genai.chat_models import ChatGoogleGenerativeAI
9
+
10
+ load_dotenv()
11
+ import os
12
+ api_url = os.getenv('PROXY_URL') + os.getenv('PROXY_PREFIX')
13
+
14
+ app = FastAPI(
15
+ title="Dev Assistant LangServe",
16
+ version="1.0",
17
+ description="A simple api server using Langchain's Runnable interfaces",
18
+ root_path_in_servers=True,
19
+ root_path=api_url,
20
+ debug=True,
21
+ )
22
+
23
+ @app.get("/")
24
+ async def root():
25
+ # return json response
26
+ return {"message": "Dev Assistant LangServe is up and running!"}
27
+
28
+ add_routes(
29
+ path = "/openai",
30
+ app = app,
31
+ runnable= ChatOpenAI(model="gpt-4-1106-preview"),
32
+ disabled_endpoints=[]
33
+ )
34
+
35
+ add_routes(
36
+ path = "/google",
37
+ app = app,
38
+ runnable= ChatGoogleGenerativeAI(model="gemini-pro"),
39
+ disabled_endpoints=[]
40
+ )
41
+
42
+ if __name__ == "__main__":
43
+ import uvicorn
44
+ uvicorn.run(app, host="localhost", port=7860, root_path=api_url)
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "dev-assistant-langserve"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["Luciano Tonet <[email protected]>"]
6
+ readme = "README.md"
7
+ packages = [
8
+ { include = "app" },
9
+ ]
10
+
11
+ [tool.poetry.dependencies]
12
+ python = "3.11.6"
13
+ uvicorn = "^0.23.2"
14
+ pydantic = "1.10.13"
15
+ python-dotenv = "^1.0.0"
16
+ langchain-google-genai = "^0.0.6"
17
+ pillow = "^10.1.0"
18
+ fastapi = "^0.105.0"
19
+ openai = "^1.6.1"
20
+ google = "^3.0.0"
21
+ langserve = {extras = ["all"], version = "^0.0.39"}
22
+
23
+
24
+ [tool.poetry.group.dev.dependencies]
25
+ langchain-cli = ">=0.0.15"
26
+
27
+ [build-system]
28
+ requires = ["poetry-core"]
29
+ build-backend = "poetry.core.masonry.api"