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

fix: Dockerfile of llmsearch and docker-comopse.yml for renaming #8

Merged
merged 4 commits into from
Oct 15, 2024
Merged
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
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM semantic-search-base:latest
FROM llmsearch-base:latest

WORKDIR /app

Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ WORKDIR /app
COPY requirements.txt requirements_production.txt ./

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu124
RUN pip install --no-cache-dir -r requirements_production.txt

# Copy the rest of your application code to the container
Expand Down
24 changes: 12 additions & 12 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
services:
postgres:
container_name: ss-postgres
container_name: llmsearch-postgres
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=ssdb
- POSTGRES_DB=llmsearchdb
# networks:
# - semantic-search
# - llmsearch
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- 35432:5432
restart: always

pgadmin:
container_name: ss-pgadmin
container_name: llmsearch-pgadmin
image: dpage/pgadmin4:latest
environment:
- [email protected]
- PGADMIN_DEFAULT_PASSWORD=123456
# networks:
# - semantic-search
# - llmsearch
volumes:
- pgadmin-data:/var/lib/pgadmin
ports:
- 35050:80
restart: always

elasticsearch:
container_name: ss-elasticsearch
container_name: llmsearch-elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:8.15.0
environment:
- discovery.type=single-node
Expand All @@ -41,12 +41,12 @@ services:
- "39200:9200"
- "39300:9300"
# networks:
# - semantic-search
# - llmsearch
volumes:
- esdata:/usr/share/elasticsearch/data

# opensearch-node1:
# container_name: ss-opensearch-node1
# container_name: llmsearch-opensearch-node1
# image: opensearchproject/opensearch:2.5.0 # You can choose the version you need
# environment:
# - cluster.name=opensearch-cluster
Expand All @@ -70,26 +70,26 @@ services:
# - "39200:9200" # OpenSearch REST API
# - "39600:9600" # Performance Analyzer
# # networks:
# # - semantic-search
# # - llmsearch
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:9200"]
# interval: 30s
# timeout: 10s
# retries: 5

# opensearch-dashboards:
# container_name: ss-opensearch-dashboards
# container_name: llmsearch-opensearch-dashboards
# image: opensearchproject/opensearch-dashboards:2.5.0
# ports:
# - "35601:5601" # OpenSearch Dashboards
# environment:
# OPENSEARCH_HOSTS: '["http://opensearch-node1:9200"]'
# OPENSEARCH_SECURITY_ADMIN_PASSWORD: admin_password # Set the admin password here for dashboards
# # networks:
# # - semantic-search
# # - llmsearch

# networks:
# semantic-search:
# llmsearch:
# driver: bridge

volumes:
Expand Down
33 changes: 23 additions & 10 deletions src/clients/openai.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import openai
from typing import Optional, List


class OpenAIClient:
def __init__(self, api_key: str, model: str):
"""
Expand All @@ -14,7 +14,13 @@ def __init__(self, api_key: str, model: str):
openai.api_key = api_key
self.model = model

def generate(self, prompt: str, model: str, max_tokens: Optional[int] = 150, temperature: Optional[float] = 1.0) -> Optional[str]:
def generate(
self,
prompt: str,
model: str,
max_tokens: Optional[int] = 150,
temperature: Optional[float] = 1.0,
) -> Optional[str]:
"""
Sends a request to OpenAI's API to generate text based on the input prompt.

Expand All @@ -31,9 +37,13 @@ def generate(self, prompt: str, model: str, max_tokens: Optional[int] = 150, tem
model=self.model,
prompt=prompt,
max_tokens=max_tokens,
temperature=temperature
temperature=temperature,
)
return (
response.choices[0].text.strip()
if response and len(response.choices) > 0
else None
)
return response.choices[0].text.strip() if response and len(response.choices) > 0 else None
except Exception as e:
print(f"Error during the request to OpenAI: {e}")
return None
Expand All @@ -49,11 +59,12 @@ def get_embedding(self, text: str) -> Optional[List[float]]:
list: A list of floats representing the embedding vector, or None if the request fails.
"""
try:
response = openai.Embedding.create(
model=self.model,
input=text
response = openai.Embedding.create(model=self.model, input=text)
return (
response.data[0]["embedding"]
if response and "data" in response and len(response.data) > 0
else None
)
return response.data[0]['embedding'] if response and 'data' in response and len(response.data) > 0 else None
except Exception as e:
print(f"Error during the request to OpenAI for embedding: {e}")
return None
Expand All @@ -68,6 +79,7 @@ def update_model(self, new_model: str) -> None:
self.model = new_model
print(f"Updated model to: {self.model}")


# Example usage:
if __name__ == "__main__":
# Initialize the client
Expand All @@ -80,11 +92,12 @@ def update_model(self, new_model: str) -> None:
print(f"Generated Text: {generated_text}")

# Example 2: Get embeddings for input text
input_text = "Quantum mechanics and general relativity are fundamental theories in physics."
input_text = (
"Quantum mechanics and general relativity are fundamental theories in physics."
)
embedding = client.get_embedding(input_text)
if embedding:
print(f"Embedding: {embedding}")

# Example 3: Update the model used by the client
client.update_model("text-embedding-ada-002")

Loading