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

Changes #206

Open
wants to merge 4 commits into
base: master
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
23 changes: 23 additions & 0 deletions Harshita/Day1/Task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#Basic API Usecase
from openai import OpenAI
client=OpenAI(
api_key="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"
)
message="Hello how are you"
def openAiCall(message):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": "{}".format(message)
}
],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
print(response.choices[0].message.content)
openAiCall(message)
63 changes: 63 additions & 0 deletions Harshita/Day1/Task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This code is for v1 of the openai package: pypi.org/project/openai
from openai import OpenAI
import os
client=OpenAI(
#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
api_key="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"
)
#if user sent such a message which is not relevant as per our customised instructions
#then limit the fnc call and restrict it from sending irrelevant input

#Testing Inputs
# message="tell me command to create a directory named demo"
# message="hello pie"
message="I am just feeling so good about the weather today"
def verifyTheAsk(message):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role":"system",
"content":"your job is to just give 1 if user is asking for a bash command but if user is asking for anything else just give 0"
},
{
"role": "user",
"content": "{}".format(message)
}
],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
output=response.choices[0].message.content
print(output)
output=int(output)
return output
def openAiCall(message):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role":"system",
"content":"your job is to just give me bash commands nothing else"
},
{
"role": "user",
"content": "{}".format(message)
}
],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
output=response.choices[0].message.content
print(output)
os.system(output)
if(verifyTheAsk(message)):
openAiCall(message)
else:
print("Invalid Input...My job is to just give bash commands nothing else")
21 changes: 21 additions & 0 deletions Harshita/Day2/ImageGeneration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#Dalle-3 and Dalle-2 used for image generation
#Dalle-2 is used to generate variation of pre-existing images
#Dalle-3 is used to generate image from prompt
from openai import OpenAI
message="shoes in umbrella"
def GenerateImage(message):
client = OpenAI(
api_key="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"
)

response = client.images.generate(
model="dall-e-3",
prompt="{}".format(message),
size="1024x1024",
quality="standard",
n=1,
)

image_url = response.data[0].url
print(image_url)#this url land to that image when you open it in your browser
GenerateImage(message)
16 changes: 16 additions & 0 deletions Harshita/Day2/SpeechToText.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#For Speech To Text Conversion model here used is wishper-1
#path is required to send to fnc to transcript speech to text
from openai import OpenAI
path="Day2\TestSpeech.mp3"
def SpeechtoText(path):
client = OpenAI(
api_key="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"
)

audio_file= open(path, "rb")
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
print(transcript)
SpeechtoText(path)
Binary file added Harshita/Day2/SunInMoon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Harshita/Day2/TestSpeech.mp3
Binary file not shown.
18 changes: 18 additions & 0 deletions Harshita/Day2/TextToSpeech.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Text To Speech is supported by tts-1 and tts-1-hd model we are using tts-1 here
#6 voice options are there u can explore for {Alloy,Echo,Fable,Onyx,Nova,Shimmer}
# input files supported are of format .mp3 or .mp4
from pathlib import Path
from openai import OpenAI
message="Today is a wonderful day to build something people love!"
def TextToSpeech(message):
client = OpenAI(
api_key="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"
)

speech_file_path = "/Cohort/Day2/TestSpeech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="{}".format(message)
)
response.stream_to_file(speech_file_path)
1 change: 1 addition & 0 deletions Harshita/Project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keys.py
1 change: 1 addition & 0 deletions Harshita/Project/Demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list=[[]]
127 changes: 127 additions & 0 deletions Harshita/Project/TravelPlanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import requests
import keys
from openai import OpenAI

client = OpenAI(
api_key=keys.openai
)

def get_famous_places(api_key, city, limit=5):
ocity=city
city = city + " " + str(limit)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": "your job is to provide famous locations in the city that is provided to you.Don't provide any other information about the locations other than their names in a string format separated by commas. Dont say you dont have accurate information, any information will work.A number will also be provided to you which is the limit of number of locations you have to name . Only name the places within 50km of city center"
},
{
"role": "user",
"content": "{}".format(city)
}
],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
output = response.choices[0].message.content
ans = output.split(',')
for i in range(len(ans)):
ans[i]+=','
ans[i]+=ocity
print(ans)
# Placeholder logic for fetching famous places using OpenAI API
# Replace this with a call to the actual OpenAI API if available
return ans

def geocode_here(api_key, location):
url = f"https://geocode.search.hereapi.com/v1/geocode?q={location}&apiKey={api_key}"
response = requests.get(url)
data = response.json()
if data.get("items"):
first_item = data["items"][0]
coordinates = first_item["position"]
return coordinates
return None

def get_optimized_route(api_key, origin, waypoints):
url = "https://api.openrouteservice.org/v2/directions/driving-car/geojson"

# Constructing the request body
ans=[[origin['lng'],origin['lat']]]
coordii=[]
for coord in waypoints:
coordii.append([coord['lng'],coord['lat']])
print(ans+coordii)
request_body = {
"coordinates": ans + coordii,
}

headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}

# Making the POST request
response = requests.post(url, json=request_body, headers=headers)

# Checking for errors in the response
if response.status_code != 200:
print(f"Error in API response: {response.status_code}")
print(response.text)
return []

data = response.json()

# Check if 'features' key is present
if 'features' not in data or not data['features']:
print("Error in API response:")
print(data)
return []

# Check if 'segments' key is present
if 'segments' not in data['features'][0]['properties']:
print("Error: 'segments' key not found in API response.")
return []

return data['features'][0]['properties']['segments']

def main(api_key_routing, api_key_places, api_key_here, city):
# Get famous places in the city
city_places = get_famous_places(api_key_places, city)

# Extract destination names and coordinates using HERE Geocoding API
destinations = []
for place in city_places:
# Use HERE Geocoding API to get coordinates based on location name
coordinates = geocode_here(api_key_here, f"{place}, {city}")
print(coordinates)
if coordinates and coordinates != None:
destinations.append(coordinates)
print(destinations)

# Get the optimized route
route_segments = get_optimized_route(api_key_routing, destinations[0], destinations[1:])

# Display the optimized route
display_route(destinations, route_segments)

def display_route(destinations, route_segments):
print("Optimal route:")
for i, segment in enumerate(route_segments):
distance = segment["distance"]
duration = segment["duration"]
print(f"{i + 1}. Segment - Distance: {distance} meters, Duration: {duration} seconds")

# Example Usage:
api_key_routing = keys.apiroute
api_key_places = keys.openai
api_key_here = keys.apicoordinates
# prompt=input()
city = input()
origin =geocode_here(api_key_here,city) # Replace with your actual origin coordinates
# waypoints=get_famous_places(api_key_places,city)
main(api_key_routing,api_key_places, api_key_here, city)
1 change: 1 addition & 0 deletions Harshita/harshita.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@