Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plants of India SQL Agent Chatbot #3

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
OPENAI_API_KEY = 'Your OpenAI API Key Here'
POI_SQL_URI = 'Your SQL URI Here'
LANGCHAIN_TRACING_V2 = true
LANGCHAIN_API_KEY = 'Your Langchain API Key Here'
LANGCHAIN_PROJECT = 'Your Langchain Project Here'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ coursera-dl/
wandb
*.ipynb
*.pem
qdrant_data/*

# don't expose env files
.env
Expand Down
2 changes: 1 addition & 1 deletion .trunk/configs/.isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[settings]
profile=black
profile=google
2 changes: 1 addition & 1 deletion .trunk/configs/.style.yapf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[style]
based_on_style = google
column_limit = 120
column_limit = 140
indent_width = 2
1 change: 0 additions & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ lint:
paths:
- .github/**/*
- .trunk/**/*
- mkdocs.yml
- .DS_Store
- .vscode/**/*
- README.md
Expand Down
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use an official Python runtime as a parent image
FROM python:3.10-slim

# Set the working directory in the container
WORKDIR /usr/src/app


# Copy the requirements file first to leverage Docker cache
COPY ai_ta_backend/requirements.txt .

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

# Mkdir for sqlite db
RUN mkdir -p /usr/src/app/db

# Copy the rest of the local directory contents into the container
COPY . .

# Set the Python path to include the ai_ta_backend directory
ENV PYTHONPATH="${PYTHONPATH}:/usr/src/app/ai_ta_backend"

# Make port 8000 available to the world outside this container
EXPOSE 8000

# Run the application using Gunicorn with specified configuration
CMD ["gunicorn", "--workers=1", "--threads=100", "--worker-class=gthread", "ai_ta_backend.main:app", "--timeout=1800", "--bind=0.0.0.0:8000"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Architecture diagram of Flask + Next.js & React hosted on Vercel.

Automatic [API Reference](https://uiuc-chatbot.github.io/ai-ta-backend/reference/)

## Docker Deployment

1. Just run Docker Compose `docker compose up --build`

Works on version: `Docker Compose version v2.27.1-desktop.1`

Works on Apple Silicon M1 `aarch64`, and `x86`.

## 📣 Development

1. Rename `.env.template` to `.env` and fill in the required variables
Expand All @@ -36,3 +44,4 @@ The docs are auto-built and deployed to [our docs website](https://uiuc-chatbot.
'url': doc.metadata.get('url'), # wouldn't this error out?
'base_url': doc.metadata.get('base_url'),
```

35 changes: 12 additions & 23 deletions ai_ta_backend/beam/OpenaiEmbeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
# # from langchain.vectorstores import Qdrant
# # from qdrant_client import QdrantClient, models


# class OpenAIAPIProcessor:

# def __init__(self, input_prompts_list, request_url, api_key, max_requests_per_minute, max_tokens_per_minute,
Expand Down Expand Up @@ -225,9 +224,9 @@
# task_list.append(task)
# next_request = None # reset next_request to empty

# # print("status_tracker.num_tasks_in_progress", status_tracker.num_tasks_in_progress)
# # logging.info("status_tracker.num_tasks_in_progress", status_tracker.num_tasks_in_progress)
# # one_task_result = task.result()
# # print("one_task_result", one_task_result)
# # logging.info("one_task_result", one_task_result)

# # if all tasks are finished, break
# if status_tracker.num_tasks_in_progress == 0:
Expand Down Expand Up @@ -263,7 +262,6 @@

# self.cleaned_results: List[str] = extract_context_from_results(self.results)


# def extract_context_from_results(results: List[Any]) -> List[str]:
# assistant_contents = []
# total_prompt_tokens = 0
Expand All @@ -282,10 +280,8 @@

# return assistant_contents


# # dataclasses


# @dataclass
# class StatusTracker:
# """Stores metadata about the script's progress. Only one instance is created."""
Expand All @@ -299,7 +295,6 @@
# num_other_errors: int = 0
# time_of_last_rate_limit_error: float = 0 # used to cool off after hitting rate limits


# @dataclass
# class APIRequest:
# """Stores an API request's inputs, outputs, and other metadata. Contains a method to make an API call."""
Expand Down Expand Up @@ -360,10 +355,8 @@

# return data


# # functions


# def api_endpoint_from_url(request_url: str):
# """Extract the API endpoint from the request URL."""
# if 'text-embedding-ada-002' in request_url:
Expand All @@ -372,14 +365,12 @@
# match = re.search('^https://[^/]+/v\\d+/(.+)$', request_url)
# return match[1] # type: ignore


# def append_to_jsonl(data, filename: str) -> None:
# """Append a json payload to the end of a jsonl file."""
# json_string = json.dumps(data)
# with open(filename, "a") as f:
# f.write(json_string + "\n")


# def num_tokens_consumed_from_request(
# request_json: dict,
# api_endpoint: str,
Expand Down Expand Up @@ -432,15 +423,13 @@
# else:
# raise NotImplementedError(f'API endpoint "{api_endpoint}" not implemented in this script')


# def task_id_generator_function():
# """Generate integers 0, 1, 2, and so on."""
# task_id = 0
# while True:
# yield task_id
# task_id += 1


# if __name__ == '__main__':
# pass

Expand Down Expand Up @@ -496,8 +485,8 @@
# # total_prompt_tokens = 0
# # total_completion_tokens = 0

# # print("Results, end of main: ", oai.results)
# # print("-"*50)
# # logging.info("Results, end of main: ", oai.results)
# # logging.info("-"*50)

# # # jsonObject = json.loads(oai.results)
# # for element in oai.results:
Expand All @@ -509,21 +498,21 @@
# # total_prompt_tokens += item['usage']['prompt_tokens']
# # total_completion_tokens += item['usage']['completion_tokens']

# # print("Assistant Contents:", assistant_contents)
# # print("Total Prompt Tokens:", total_prompt_tokens)
# # print("Total Completion Tokens:", total_completion_tokens)
# # logging.info("Assistant Contents:", assistant_contents)
# # logging.info("Total Prompt Tokens:", total_prompt_tokens)
# # logging.info("Total Completion Tokens:", total_completion_tokens)
# # turbo_total_cost = (total_prompt_tokens * 0.0015) + (total_completion_tokens * 0.002)
# # print("Total cost (3.5-turbo):", (total_prompt_tokens * 0.0015), " + Completions: ", (total_completion_tokens * 0.002), " = ", turbo_total_cost)
# # logging.info("Total cost (3.5-turbo):", (total_prompt_tokens * 0.0015), " + Completions: ", (total_completion_tokens * 0.002), " = ", turbo_total_cost)

# # gpt4_total_cost = (total_prompt_tokens * 0.03) + (total_completion_tokens * 0.06)
# # print("Hypothetical cost for GPT-4:", (total_prompt_tokens * 0.03), " + Completions: ", (total_completion_tokens * 0.06), " = ", gpt4_total_cost)
# # print("GPT-4 cost premium: ", (gpt4_total_cost / turbo_total_cost), "x")
# # logging.info("Hypothetical cost for GPT-4:", (total_prompt_tokens * 0.03), " + Completions: ", (total_completion_tokens * 0.06), " = ", gpt4_total_cost)
# # logging.info("GPT-4 cost premium: ", (gpt4_total_cost / turbo_total_cost), "x")
# '''
# Pricing:
# GPT4:
# GPT4:
# * $0.03 prompt
# * $0.06 completions
# 3.5-turbo:
# 3.5-turbo:
# * $0.0015 prompt
# * $0.002 completions
# '''
Expand Down
Loading