Skip to content

Commit

Permalink
update fastapi server
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanuozdemir committed Jun 29, 2024
1 parent 57c70fb commit 0485d83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions semantic-search-fastapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime

import openai
import pinecone
from pinecone import Pinecone, ServerlessSpec
import uvicorn
from dotenv import load_dotenv
from fastapi import FastAPI
Expand All @@ -21,28 +21,31 @@
openai.api_key = os.getenv("OPENAI_API_KEY")
pinecone_key = os.getenv("PINECONE_API_KEY")


app = FastAPI()

INDEX_NAME = 'semantic-search'
ENGINE = 'text-embedding-ada-002'

if pinecone_key:
pinecone.init(api_key=pinecone_key, environment="us-west1-gcp")

if not INDEX_NAME in pinecone.list_indexes():
pinecone.create_index(
INDEX_NAME, # The name of the index to create.
dimension=1536, # The dimensionality of the vectors that will be indexed.
metric='cosine', # The similarity metric to use when searching the index.
pod_type="p1" # The type of Pinecone pod to use for hosting the index (in this case, a p1 pod).

pc = Pinecone(
api_key=pinecone_key
)
if INDEX_NAME not in pc.list_indexes().names():
print(f'Creating index {INDEX_NAME}')
pc.create_index(
name=INDEX_NAME, # The name of the index
dimension=3072, # The dimensionality of the vectors for our OpenAI embedder
metric='cosine', # The similarity metric to use when searching the index
spec=ServerlessSpec(
cloud='aws',
region='us-west-2'
)
)
print('Pinecone index created')
else:
print('Pinecone index already exists')

# Store the index as a variable
index = pinecone.Index(INDEX_NAME)

index = pc.Index(name=INDEX_NAME)

def my_hash(s):
# Return the MD5 hash of the input string as a hexadecimal string
Expand Down
2 changes: 1 addition & 1 deletion semantic-search-fastapi/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fastapi==0.70.1
uvicorn==0.16.0
openai==0.27.2
pinecone-client==2.0.13
pinecone-client==4.0.0
matplotlib
plotly
scipy
Expand Down

0 comments on commit 0485d83

Please sign in to comment.