ryanbalch commited on
Commit
0833ce4
·
1 Parent(s): 7ee3a30

adding documentation for project

Browse files
api/README.md CHANGED
@@ -1,18 +1,210 @@
 
1
 
2
- # deploy
3
 
4
- we need to do this in order:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  ```bash
7
- # build the final image
8
- make build-prod
9
- # huggingface needs to either build the image itself, or we need to pull it from somewhere
10
- # atm that's github container registry
11
- # so we push it there
12
- make push-prod-ghcr
13
- # now we need to trigger a build in that repo
14
- cd IFX-huge-league && make trigger-build
15
  ```
16
 
17
- then wait for it to finish building
18
- https://huggingface.co/spaces/ryanbalch/IFX-huge-league?logs=container
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Huge IFX API
2
 
3
+ An AI-powered sports fan assistant that creates natural language, multimodal, and personalized experiences around professional sports teams, players, games, rules, and fan communities. The app delivers conversational responses enhanced with visuals and session memory.
4
 
5
+ **Fictional League:** Huge League
6
+ - International soccer league, 23-player squads, 4-3-3 base formation.
7
+ - Teams:
8
+ - Yucatán Force (Mérida, Mexico): Mayan pride, fortress stadium "El Templo del Sol".
9
+ - Tierra Alta FC (San José, Costa Rica): Highlanders, eco-friendly, smart play.
10
+ - Everglade FC (Miami, USA): Flashy, wild, South Florida flair.
11
+ - Fraser Valley United (Abbotsford, Canada): Vineyard roots, top youth academy.
12
+
13
+ ---
14
+
15
+ ## Table of Contents
16
+
17
+ - [Features](#features)
18
+ - [Architecture](#architecture)
19
+ - [Tech Stack](#tech-stack)
20
+ - [Setup](#setup)
21
+ - [Deployment](#deployment)
22
+ - [API Usage](#api-usage)
23
+ - [Prompt Management (Freeplay)](#prompt-management-freeplay)
24
+ - [Memory (Zep)](#memory-zep)
25
+ - [Agents (LangGraph)](#agents-langgraph)
26
+ - [LLM (OpenAI)](#llm-openai)
27
+ - [Development & Contributing](#development--contributing)
28
+ - [License](#license)
29
+
30
+ ---
31
+
32
+ ## Features
33
+
34
+ - Conversational AI assistant for Huge League soccer fans
35
+ - Multimodal responses (text, visuals)
36
+ - Personalized session memory
37
+ - Prompt management and logging
38
+ - Modular agent-based workflow
39
+
40
+ ---
41
+
42
+ ## Architecture
43
+
44
+ ```mermaid
45
+ flowchart TD
46
+ UI[Gradio UI (HuggingFace Spaces)]
47
+ API[FastAPI (server.py)]
48
+ Workflow[LangGraph Agent Workflow]
49
+ Freeplay[Prompt Management (Freeplay)]
50
+ Zep[Memory (Zep)]
51
+ OpenAI[LLM (OpenAI)]
52
+ Tools[Custom Tools]
53
+ UI --> Workflow
54
+ Workflow --> Freeplay
55
+ Workflow --> Zep
56
+ Workflow --> OpenAI
57
+ Workflow --> Tools
58
+ ```
59
+
60
+ - **UI:** Gradio-based, runs via `server_gradio.py`
61
+ - **Workflow:** Orchestrated by LangGraph (`workflows/base.py`)
62
+ - **Prompt Management:** Freeplay (`utils/freeplay_helpers.py`)
63
+ - **Memory:** Zep (`utils/zep_helpers.py`)
64
+ - **LLM:** OpenAI (gpt-4o-mini)
65
+ - **Tools:** Player/Game search (`tools/`)
66
+
67
+ ---
68
+
69
+ ## Tech Stack
70
+
71
+ - [Gradio](https://gradio.app/) (HuggingFace Spaces)
72
+ - [FastAPI](https://fastapi.tiangolo.com/) (not used b/c we went with gradio)
73
+ - [Freeplay](https://freeplay.ai/) (Prompt management)
74
+ - [Zep](https://getzep.com/) (Session memory)
75
+ - [LangGraph](https://langchain-ai.github.io/langgraph/) (Agent workflow)
76
+ - [OpenAI](https://openai.com/) (LLM)
77
+ - [Docker](https://www.docker.com/), [Poetry](https://python-poetry.org/) for dependency management
78
+
79
+ ---
80
+
81
+ ## Setup
82
+
83
+ **Prerequisites:**
84
+ - [Docker](https://www.docker.com/) installed
85
+
86
+ **Quickstart:**
87
 
88
  ```bash
89
+ make build
90
+ make up
 
 
 
 
 
 
91
  ```
92
 
93
+ - The app will be available at [http://localhost:8000/](http://localhost:8000/)
94
+
95
+ **Environment Variables:**
96
+ - See `.env.example` (TODO: Document required env vars for Freeplay, Zep, OpenAI, etc.)
97
+ - Ask Liss for env vars.
98
+
99
+ ---
100
+
101
+ ## Deployment
102
+
103
+ ### HuggingFace Spaces
104
+
105
+ App is hosted at: [https://huggingface.co/spaces/ryanbalch/IFX-huge-league](https://huggingface.co/spaces/ryanbalch/IFX-huge-league)
106
+
107
+ To deploy:
108
+
109
+ 1. **Clone this repo** under your HuggingFace repo (in the `IFX-huge-league` folder). You will need it for deploys, etc.
110
+ 2. **Deployment Targets:**
111
+ - GitHub: [aliss77777/IFX-sandbox](https://github.com/aliss77777/IFX-sandbox/tree/huge-league)
112
+ - HuggingFace: [ryanbalch/IFX-huge-league](https://huggingface.co/spaces/ryanbalch/IFX-huge-league/tree/main)
113
+ - Docker images: `ghcr.io/rbalch/huge-ifx-api:prod`
114
+
115
+ 3. **Deployment Steps:**
116
+
117
+ ```bash
118
+ # build the final image
119
+ make build-prod
120
+ # push to GitHub Container Registry
121
+ make push-prod-ghcr
122
+ # trigger a build in the HuggingFace repo
123
+ cd IFX-huge-league && make trigger-build
124
+ ```
125
+
126
+ Then wait for the build to finish: [HuggingFace container logs](https://huggingface.co/spaces/ryanbalch/IFX-huge-league?logs=container)
127
+
128
+ ---
129
+
130
+ ## API Usage
131
+
132
+ - **Gradio UI:** Main entrypoint is `server_gradio.py`.
133
+ Launches the conversational interface for Huge League fans.
134
+ - **FastAPI:** `server.py` provides a minimal API (mostly for development/debug).
135
+
136
+ ### Endpoints
137
+
138
+ | Path | Method | Description |
139
+ |--------|--------|---------------------|
140
+ | `/` | GET | Healthcheck/home |
141
+
142
+ (TODO: Document additional endpoints if present)
143
+
144
+ ---
145
+
146
+ ## Prompt Management (Freeplay)
147
+
148
+ - Integrated via `utils/freeplay_helpers.py`
149
+ - Prompts are fetched, formatted, and logged using Freeplay.
150
+ - See `scripts/freeplay_playground.py` for usage examples.
151
+
152
+ ---
153
+
154
+ ## Memory (Zep)
155
+
156
+ - Integrated via `utils/zep_helpers.py`
157
+ - Session/user memory managed via Zep.
158
+ - See `scripts/zep_playground.py` for usage examples.
159
+
160
+ ---
161
+
162
+ ## Agents (LangGraph)
163
+
164
+ - Workflow orchestrated in `workflows/base.py` using LangGraph.
165
+ - Integrates LLM, memory, prompt management, and tools.
166
+
167
+ ---
168
+
169
+ ## LLM (OpenAI)
170
+
171
+ - Uses OpenAI models (e.g., `gpt-4o-mini`) via LangChain/LangGraph.
172
+ - API keys required. (TODO: Document setup)
173
+
174
+ ---
175
+
176
+ ## Development & Contributing
177
+
178
+ - All development is Dockerized.
179
+ - Use Poetry for dependency management (`poetry add <pkg>` inside the container).
180
+ - Follow PEP8, prefer two blank lines between unrelated classes/functions.
181
+ - See `Makefile` for available commands.
182
+
183
+ ---
184
+
185
+ ## Makefile Commands
186
+
187
+ The following `make` commands are available for development, build, and deployment workflows:
188
+
189
+ | Command | Description |
190
+ |-----------------------|-------------|
191
+ | `make build` | Build all Docker images using `docker-compose.yaml`. |
192
+ | `make build-update` | Remove `poetry.lock`, rebuild Docker image, and extract new lock file from the container. **Note:** This is not needed for local development. Only use if you're trying to update dependencies. |
193
+ | `make up` | Start all services using Docker Compose. |
194
+ | `make command` | Open an interactive shell inside the running `huge-ifx-api` container. |
195
+ | `make command-raw` | Run a bash shell in a new container using Docker Compose (not the running one). |
196
+ | `make clean-requirements` | Remove the local `poetry.lock` file. |
197
+ | `make extract-lock` | Extract the `poetry.lock` file from a built container to your local directory. **Note:** This is only needed if you've been deleting the lock file because build will not have access to local lock file. |
198
+ | `make build-prod` | Build the Docker image for the `runtime` stage in `api/Dockerfile`, tagged as `huge-ifx-api:prod`. Used for production deploys. |
199
+ | `make up-build-prod` | Build and run the production image locally, mapping ports 7860 and 8000, with `.env` and `DEV_MODE=true`. |
200
+ | `make push-prod-ghcr` | Tag and push the production image to GitHub Container Registry at `ghcr.io/rbalch/huge-ifx-api:prod`. |
201
+
202
+ **Typical workflow:**
203
+ - Use `make build` and `make up` for local development.
204
+ - Use `make build-prod`, `make push-prod-ghcr`, and `make trigger-build` (in the HuggingFace repo) for production deployment.
205
+
206
+ ---
207
+
208
+ ## License
209
+
210
+ (TODO: Add license info)
api/tools/game_search.py CHANGED
@@ -1,3 +1,11 @@
 
 
 
 
 
 
 
 
1
  from langchain_core.tools import BaseTool
2
  from pydantic import BaseModel, Field
3
  from langchain_core.documents import Document
 
1
+ """
2
+ Game Search Tool
3
+
4
+ This module defines the GameSearchTool, a LangChain-compatible tool for searching soccer games and their related events
5
+ from the project's vector store. It includes a schema for specifying game queries, and provides both synchronous and
6
+ asynchronous search methods. Used by the agent workflow to retrieve structured game/event data for downstream processing.
7
+ """
8
+
9
  from langchain_core.tools import BaseTool
10
  from pydantic import BaseModel, Field
11
  from langchain_core.documents import Document
api/tools/player_search.py CHANGED
@@ -1,3 +1,12 @@
 
 
 
 
 
 
 
 
 
1
  from pydantic import BaseModel, Field
2
  from langchain.tools import BaseTool, StructuredTool, tool
3
  from langchain_core.documents import Document
 
1
+ """
2
+ Player Search Tool
3
+
4
+ This module defines the PlayerSearchTool, a LangChain-compatible tool for searching soccer players in the fictional Huge League
5
+ using the project's vector store. It includes a schema for flexible player queries (by name, position, team, or number), supports
6
+ random/team-based queries, and provides both synchronous and asynchronous search methods. Used by the agent workflow to retrieve
7
+ player profiles, stats, and related data for downstream processing.
8
+ """
9
+
10
  from pydantic import BaseModel, Field
11
  from langchain.tools import BaseTool, StructuredTool, tool
12
  from langchain_core.documents import Document