Skip to content

Commit

Permalink
updating python example
Browse files Browse the repository at this point in the history
  • Loading branch information
ardan-bkennedy committed Jun 5, 2024
1 parent 74fd7b0 commit 012c4c7
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions fern/docs/pages/sdks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,42 @@ You can find the SDK docs and package information using this link.
#### Python Code Example

```python
import predictionguard as pg

# Initialize a Prediction Guard client.
client = Client(token=<your access token>)

# Create some examples illustrating the kind of predictions you
# want to make (domain/ use case specific).
examples = [
{
"input": {
"phrase": "I'm so excited about Prediction Guard. It's gonna be awesome!"
},
"output": {
"sentiment": "POS"
}
},
{
"input": {
"phrase": "AI development without Prediction Guard is bad. It's really terrible."
},
"output": {
"sentiment": "NEG"
}
}
import json
import os

from predictionguard import PredictionGuard

# You can set you Prediction Guard API Key as an env variable,
# or when creating the client object
os.environ["PREDICTIONGUARD_API_KEY"]

client = PredictionGuard(
api_key="<your Prediction Guard API Key"
)

messages = [
{
"role": "system",
"content": "You are a helpful chatbot that helps people learn."
},
{
"role": "user",
"content": "What is a good way to learn to code?"
}
]

# Create a prediction "proxy." This proxy will save your examples, evaluate
# SOTA models to find the best one for your use case, and expose the best model
# at an endpoint corresponding to the proxy.
client.create_proxy(task='sentiment', name='my-sentiment-proxy', examples=examples)
result = client.chat.completions.create(
"model": "Hermes-2-Pro-Llama-3-8B",
"messages": messages,
"max_tokens": 100
)

# Now your ready to start getting reliable, future proof predictions. No fuss!
client.predict(name='test-client-sentiment4', data={
"phrase": "Isn't this great! I'm so happy I'm using Prediction Guard"
})
print(json.dumps(
result,
sort_keys=True,
indent=4,
separators=(',', ': ')
))
```

#### More Python Examples
Expand Down

0 comments on commit 012c4c7

Please sign in to comment.