outlines
outlines copied to clipboard
Make `generate.json` compatible with OpenAI's function calling format
OpenAI uses a small variation on the JSON Schema specification, and we need to make our interface compatible.
@rlouf Can I pick up this task ?
By all means!
@rlouf Can you check if this is what you expected ?
I tried to run few demos mentioned in Readme. I could see model gets downloaded but nothing happen after that. I also wrote code(pasted below) to test this PR. But I couldn't run it locally. Can you guide me please ?
import outlines
import requests
def get_weather(latitude, longitude):
print ("get weather ")
response = requests.get(f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m")
data = response.json()
return data['current']['temperature_2m']
function_def = {
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for provided coordinates in celsius.",
"parameters": {
"type": "object",
"properties": {
"latitude": {"type": "number"},
"longitude": {"type": "number"}
},
"required": ["latitude", "longitude"],
"additionalProperties": False
},
"strict": True
}
}
model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct")
generator = outlines.generate.json(model, function_def)
prompt = """"Given the coordinates for Paris, France:
Latitude: 48.8566
Longitude: 2.3522
Generate the JSON to get the weather."""
result = generator(prompt)
print (result)
@rlouf It seems like you planned to do this other way. Can I close this PR ? I would like to contribute to resolve other issue. Is there any issue I can pick for first time contributor ?
What do you mean by planned to do this another way?
Sorry I misunderstood when you removed tags. Can you review PR draft and let me know if that's what you are expecting ?