Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ChatGPT Python API for sales

This is an AI app to find **real-time** discounts/deals/sales prices from various online markets around the world. The project
exposes an HTTP REST endpoint to answer user queries about current sales like [Amazon deals](https://www.amazon.com/gp/goldbox?ref_=nav_cs_gb) in a specific location or from the given any input file such as (CSV, Jsonlines, PDF, Markdown, Txt). It uses Pathway’s [LLM App features](https://github.com/pathwaycom/llm-app) to build real-time LLM(Large Language Model)-enabled data pipeline in Python and join data from multiple input sources, leverages OpenAI API [Embeddings](https://platform.openai.com/docs/api-reference/embeddings) and [Chat Completion](https://platform.openai.com/docs/api-reference/completions) endpoints to generate AI assistant responses.
exposes an HTTP REST endpoint to answer user queries about current sales like [Amazon deals](https://www.amazon.com/gp/goldbox?ref_=nav_cs_gb) in a specific location or from the given any input file such as (CSV, Jsonlines, PDF, Markdown, Txt). It uses Pathway’s [LLM App features](https://github.com/pathwaycom/pathway) to build real-time LLM(Large Language Model)-enabled data pipeline in Python and join data from multiple input sources, leverages OpenAI API [Embeddings](https://platform.openai.com/docs/api-reference/embeddings) and [Chat Completion](https://platform.openai.com/docs/api-reference/completions) endpoints to generate AI assistant responses.

Currently, the project supports two types of data sources and it is **possible to extend sources** by adding custom input connectors:

Expand Down Expand Up @@ -86,7 +86,7 @@ pw.run()
- Real-time data.
- Including discount information.

The model might not answer such queries properly. Because it is not aware of the context or historical data or it needs additional details. In this case, you can use LLM App efficiently to give context to this search or answer process. See how LLM App [works](https://github.com/pathwaycom/llm-app#how-it-works).
The model might not answer such queries properly. Because it is not aware of the context or historical data or it needs additional details. In this case, you can use Pathway LLM xpack efficiently to give context to this search or answer process. See how LLM Application built with Pathway [works](https://github.com/pathwaycom/llm-app#how-it-works).

For example, a typical response you can get from the OpenAI [Chat Completion endpoint](https://platform.openai.com/docs/api-reference/chat) or [ChatGPT UI](https://chat.openai.com/) interface without context is:

Expand Down Expand Up @@ -250,4 +250,4 @@ Ship Date: 2024-08-09

1. [Set environment variables](#step-2-set-environment-variables)
2. From the project root folder, open your terminal and run `docker compose up`.
3. Navigate to `localhost:8501` on your browser when docker installion is successful.
3. Navigate to `localhost:8501` on your browser when docker installation is successful.
31 changes: 20 additions & 11 deletions common/openaiapi_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from dotenv import load_dotenv
import os
from llm_app.model_wrappers import OpenAIEmbeddingModel, OpenAIChatGPTModel
import pathway as pw
from pathway.xpacks.llm.embedders import OpenAIEmbedder
from pathway.xpacks.llm.llms import OpenAIChat, prompt_chat_single_qa

load_dotenv()

Expand All @@ -13,17 +15,24 @@


def openai_embedder(data):
embedder = OpenAIEmbeddingModel(api_key=api_key)
embedder = OpenAIEmbedder(
api_key=api_key,
model=embedder_locator,
retry_strategy=pw.asynchronous.FixedDelayRetryStrategy(),
cache_strategy=pw.asynchronous.DefaultCache(),
)

return embedder.apply(text=data, locator=embedder_locator)
return embedder(data)


def openai_chat_completion(prompt):
model = OpenAIChatGPTModel(api_key=api_key)

return model.apply(
prompt,
locator=model_locator,
temperature=temperature,
max_tokens=max_tokens,
)
model = OpenAIChat(
api_key=api_key,
model=model_locator,
temperature=temperature,
retry_strategy=pw.asynchronous.FixedDelayRetryStrategy(),
cache_strategy=pw.asynchronous.DefaultCache(),
max_tokens=max_tokens,
)

return model(prompt_chat_single_qa(prompt))
4 changes: 3 additions & 1 deletion examples/rainforest/rainforestapi_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import requests
import json
import json5
from dotenv import load_dotenv
from urllib.parse import urlencode

Expand Down Expand Up @@ -29,7 +30,8 @@ def send_request(data_dir, params):
response = requests.get(get_url(params))

if response.status_code == 200:
data = response.json()
# needed because of trailing coma in returned json array
data = json5.loads(response.text)

deals_results = data.get('deals_results', [])

Expand Down
4 changes: 2 additions & 2 deletions examples/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
st.markdown("# About")
st.markdown(
"AI app to find real-time discounts from various online markets [Amazon deals](https://www.amazon.com/gp/goldbox?ref_=nav_cs_gb) in a specific location. "
"It uses Pathway’s [LLM App features](https://github.com/pathwaycom/llm-app) "
"It uses Pathway’s [LLM App features](https://github.com/pathwaycom/pathway) "
"to build real-time LLM(Large Language Model)-enabled data pipeline in Python and join data from multiple input sources\n"

)
st.markdown("[View the source code on GitHub](https://github.com/Boburmirzo/chatgpt-api-python-sales)")
st.markdown("[View the source code on GitHub](https://github.com/pathway-labs/chatgpt-api-python-sales)")

# Load environment variables
load_dotenv()
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pathway
pandas
requests
datetime
llm_app
streamlit
python-dotenv
python-dotenv
litellm
json5