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

HuggingFace Inference API support #4

Open
patel-zeel opened this issue Apr 5, 2024 · 0 comments
Open

HuggingFace Inference API support #4

patel-zeel opened this issue Apr 5, 2024 · 0 comments

Comments

@patel-zeel
Copy link

Hi,

First of all, congratulations on making such a helpful library.

Applications relying on OpenAI API keys are a bit restricted for researchers like me who have no access to the API (yet). Is it possible to extend the support to "HuggingFace (HF) Inference API" or another similar API? HF offers free API for a number of LLMs hosted by themselves.

Here is an example:

import requests

API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
headers = {"Authorization": f"Bearer {hf_token}"}

def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.json()
	
prompt = """df = pd.read_csv("data.csv")

# Plot y v/s x
"""
 
output = query({
	"inputs": prompt,
})
print(output[0]['generated_text'])

Output:

df = pd.read_csv("data.csv")

# Plot y v/s x
df.plot(x="x", y="y")
plt.show()

# Plot y v/s x with fitting line
plt.scatter(df['x'], df['y'])
plt.plot(df['x'], np.poly1d(np.polyfit(df['x'], df['y'], degree=1))(df['x']), color='r')
plt.show()

# Linear Reg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant