Skip to content

Commit

Permalink
Serverside changes, Ports etc
Browse files Browse the repository at this point in the history
  • Loading branch information
PP GPU Server authored and PP GPU Server committed Jul 8, 2024
1 parent 792308b commit a2c7c53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "pnpm with-env next build",
"build:ext": "pnpm with-env bash build-ext.sh",
"clean": "git clean -xdf .next .turbo node_modules",
"dev": "pnpm with-env next dev",
"dev": "PORT=3001 pnpm with-env next dev",
"lint": "dotenv -v SKIP_ENV_VALIDATION=1 next lint",
"lint:fix": "pnpm lint --fix",
"start": "pnpm with-env next start",
Expand Down
3 changes: 2 additions & 1 deletion frontend/apps/sample/api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ def generate_cta():
# Parse incoming data as binary
data = request.get_data()
spotify_token = request.headers.get("x-spotify-access-token", "undefined")
spotify_refresh_token = request.headers.get("x-spotify-refresh-token", "undefined")
text = data.decode("utf-8")

# response = post("http://108.181.203.191:8047/t2c/{}".format(urllib.parse.quote(text, safe="/")))
# response = post("http://108.181.203.191:8047/t2c/", json={"user_input": text})
response = post("http://108.181.203.191:8007/t2c", json={"user_input": text}, headers={"x-spotify-access-token": spotify_token})
response = post("http://108.181.203.191:8007/t2c", json={"user_input": text}, headers={"x-spotify-access-token": spotify_token, "x-spotify-refresh-token": spotify_refresh_token})

json = response.json()

Expand Down
7 changes: 5 additions & 2 deletions server/function_calling/actions/spotify_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
client_id = "642551fcd12a4d17898ce7f8310fcaa2"
#client_secret = "53520c39acb44b16962a58df6bd94e8e"
client_secret = "d93f08d1b5f944deacac371acff85ee0"
redirect_uri = "http://127.0.0.1:5000/callback"
redirect_uri = "http://108.181.203.191:3001/callback"
TOKEN_URL = 'https://accounts.spotify.com/api/token'
API_BASE_URL = 'https://api.spotify.com/v1/'
current_session = {
Expand Down Expand Up @@ -298,7 +298,10 @@ def get_available_devices(access_token):
'Authorization': f"Bearer {access_token}"
}
response = requests.get(API_BASE_URL + 'me/player/devices', headers=headers)
return response.json()
try:
return response.json()
except Exception as e:
return {}

def search_for_song(token, song_name):
url = "https://api.spotify.com/v1/search"
Expand Down
15 changes: 11 additions & 4 deletions server/function_calling/fastapi_llama3.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,28 @@ async def t2c(request: Request, user_data: UserInput):
text = user_data.user_input
start_time = time()
token ={
"access_token":request.headers.get("x-spotify-access-token", "header not found")
"access_token":request.headers.get("x-spotify-access-token", "header not found"),
"refresh_token": request.headers.get("x-spotify-refresh-token", "header not found")
}
print(token)
# print(token)

conn = sqlite3.connect('key_value_store.db')
c = conn.cursor()

actions.database_handling.write_to_store("AlexaUser", json.dumps(token), conn, c)

conn.close()

output = llamaModel.process_input(text)

conn = sqlite3.connect('key_value_store.db')
c = conn.cursor()
actions.database_handling.delete_from_store("AlexaUser", conn, c)
conn.close()

print("llama time taken: {}".format(time() - start_time))
print("x-spotify-token: {}".format(request.headers.get("x-spotify-access-token", "header not found")))
# print("llama time taken: {}".format(time() - start_time))
# print("x-spotify-access-token: {}".format(request.headers.get("x-spotify-access-token", "header not found")))
print("x-spotify-refresh-token: {}".format(request.headers.get("x-spotify-refresh-token", "header not found")))
try:
qdrant = post("http://108.181.203.191:8047/vidindex", json={"user_input": text})
return {"message": output, "qdrant": qdrant.json()["message"]}
Expand Down

0 comments on commit a2c7c53

Please sign in to comment.