tommy24 commited on
Commit
719aa6f
·
1 Parent(s): 49b4dd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -37
app.py CHANGED
@@ -967,57 +967,78 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
967
  # return None
968
 
969
  # @openai_func
970
- def testing_this(name: str, number: str):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
971
  """
972
- This function ask user for their name and a random integer and returns it.
973
- @param name: The name of the user
974
- @param number: Random number entered by the user
975
  """
976
 
977
- if name is None:
978
  return "Your name must be provided, inorder to run the function call"
979
- elif number is None:
980
- return "A random number must be provided, inorder to run the function call"
981
- elif name is None and number is None :
982
- return "You must provide your name and a random number to continue."
983
  else:
984
- return "Function call successfull"
985
-
986
- # functions = [
987
- # {
988
- # "name": "get_current_weather",
989
- # "description": "Get the current weather in a given location",
990
- # "parameters": {
991
- # "type": "object",
992
- # "properties": {
993
- # "location": {
994
- # "type": "string",
995
- # "description": "The city and state, e.g. San Francisco, CA",
996
- # },
997
- # "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
998
- # },
999
- # "required": ["location"],
1000
- # },
1001
- # }
1002
- # ]
1003
 
1004
  functions = [
1005
  {
1006
- "name": "testing_this",
1007
- "description": "This function ask user for their name and a random integer and returns it",
1008
  "parameters": {
1009
  "type": "object",
1010
  "properties": {
1011
- "name": {
1012
  "type": "string",
1013
- "description": "Name of the user",
1014
  },
1015
- "number": {"type": "string", "description": "A random number"},
1016
  },
1017
- "required": ["name", "number"],
1018
  },
1019
  }
1020
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1021
 
1022
  completion = openai.ChatCompletion.create(
1023
  model="gpt-3.5-turbo",
@@ -1070,12 +1091,12 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
1070
  arguments_dict = json.loads(arguments_str)
1071
 
1072
  function_response = testing_this(
1073
- name=arguments_dict["name"],
1074
- number=arguments_dict["number"]
1075
  )
1076
 
1077
  print("FUNCTION_RESPONSE:", function_response)
1078
- print("ARGUMENTS VALUES:", arguments_dict["name"], arguments_dict["number"])
1079
  # messages.append(comp)
1080
  # messages.append({
1081
  # "role": "function",
 
967
  # return None
968
 
969
  # @openai_func
970
+ # def testing_this(name: str, number: str):
971
+ # """
972
+ # This function ask user for their name and a random integer and returns it.
973
+ # @param name: The name of the user
974
+ # @param number: Random number entered by the user
975
+ # """
976
+
977
+ # if name is None:
978
+ # return "Your name must be provided, inorder to run the function call"
979
+ # elif number is None:
980
+ # return "A random number must be provided, inorder to run the function call"
981
+ # elif name is None and number is None :
982
+ # return "You must provide your name and a random number to continue."
983
+ # else:
984
+ # return "Function call successfull"
985
+
986
+ def get_current_weather(location: str, unit: str):
987
  """
988
+ This function get's the current weather in a given location.
989
+ @param location: The name of the user
990
+ @param unit: Random number entered by the user
991
  """
992
 
993
+ if location is None:
994
  return "Your name must be provided, inorder to run the function call"
 
 
 
 
995
  else:
996
+ params = {
997
+ 'appid': '334f89b7998e8df818503b0f33085621',
998
+ 'q': location,
999
+ 'units': unit
1000
+ }
1001
+ response = requests.get('https://api.openweathermap.org/data/2.5/weather', params=params)
1002
+ if response.status_code == 200:
1003
+ return response.json()
1004
+ else:
1005
+ return None
 
 
 
 
 
 
 
 
 
1006
 
1007
  functions = [
1008
  {
1009
+ "name": "get_current_weather",
1010
+ "description": "Get the current weather in a given location",
1011
  "parameters": {
1012
  "type": "object",
1013
  "properties": {
1014
+ "location": {
1015
  "type": "string",
1016
+ "description": "The city and state, e.g. San Francisco, CA",
1017
  },
1018
+ "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
1019
  },
1020
+ "required": ["location"],
1021
  },
1022
  }
1023
  ]
1024
+
1025
+ # functions = [
1026
+ # {
1027
+ # "name": "testing_this",
1028
+ # "description": "This function ask user for their name and a random integer and returns it",
1029
+ # "parameters": {
1030
+ # "type": "object",
1031
+ # "properties": {
1032
+ # "name": {
1033
+ # "type": "string",
1034
+ # "description": "Name of the user",
1035
+ # },
1036
+ # "number": {"type": "string", "description": "A random number"},
1037
+ # },
1038
+ # "required": ["name", "number"],
1039
+ # },
1040
+ # }
1041
+ # ]
1042
 
1043
  completion = openai.ChatCompletion.create(
1044
  model="gpt-3.5-turbo",
 
1091
  arguments_dict = json.loads(arguments_str)
1092
 
1093
  function_response = testing_this(
1094
+ name=arguments_dict["location"],
1095
+ number=arguments_dict["unit"]
1096
  )
1097
 
1098
  print("FUNCTION_RESPONSE:", function_response)
1099
+ print("ARGUMENTS VALUES:", arguments_dict["location"], arguments_dict["unit"])
1100
  # messages.append(comp)
1101
  # messages.append({
1102
  # "role": "function",