-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dr_log10feedback_documentation
- Loading branch information
Showing
14 changed files
with
762 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import asyncio | ||
|
||
import litellm | ||
|
||
from log10.litellm import Log10LitellmLogger | ||
|
||
|
||
log10_handler = Log10LitellmLogger(tags=["litellm_acompletion"]) | ||
litellm.callbacks = [log10_handler] | ||
|
||
model_name = "claude-3-haiku-20240307" | ||
|
||
|
||
async def completion(): | ||
response = await litellm.acompletion( | ||
model=model_name, messages=[{"role": "user", "content": "count to 10"}], stream=True | ||
) | ||
async for chunk in response: | ||
if chunk.choices[0].delta.content: | ||
print(chunk.choices[0].delta.content, end="", flush=True) | ||
|
||
|
||
asyncio.run(completion()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import litellm | ||
|
||
from log10.litellm import Log10LitellmLogger | ||
|
||
|
||
log10_handler = Log10LitellmLogger(tags=["litellm_completion", "stream"]) | ||
litellm.callbacks = [log10_handler] | ||
response = litellm.completion( | ||
model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Count to 10."}], stream=True | ||
) | ||
for chunk in response: | ||
if chunk.choices[0].delta.content: | ||
print(chunk.choices[0].delta.content, end="", flush=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import base64 | ||
|
||
import httpx | ||
import litellm | ||
|
||
from log10.litellm import Log10LitellmLogger | ||
|
||
|
||
log10_handler = Log10LitellmLogger(tags=["litellm_image"]) | ||
litellm.callbacks = [log10_handler] | ||
|
||
image_url = "https://upload.wikimedia.org/wikipedia/commons/e/e8/Log10.png" | ||
image_media_type = "image/png" | ||
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8") | ||
|
||
|
||
model_name = ("gpt-4-vision-preview",) | ||
model_name = "claude-3-haiku-20240307" | ||
resp = litellm.completion( | ||
model=model_name, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{ | ||
"type": "image_url", | ||
"image_url": {"url": f"data:{image_media_type};base64,{image_data}"}, | ||
}, | ||
{"type": "text", "text": "What's the red curve in the figure, is it log2 or log10? Be concise."}, | ||
], | ||
} | ||
], | ||
) | ||
print(resp.choices[0].message.content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import asyncio | ||
import base64 | ||
|
||
import httpx | ||
import litellm | ||
|
||
from log10.litellm import Log10LitellmLogger | ||
|
||
|
||
log10_handler = Log10LitellmLogger(tags=["litellm_image", "stream", "async"]) | ||
litellm.callbacks = [log10_handler] | ||
|
||
image_url = "https://upload.wikimedia.org/wikipedia/commons/e/e8/Log10.png" | ||
image_media_type = "image/png" | ||
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8") | ||
|
||
model_name = "claude-3-haiku-20240307" | ||
|
||
|
||
async def completion(): | ||
resp = litellm.completion( | ||
model=model_name, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{ | ||
"type": "image_url", | ||
"image_url": {"url": f"data:{image_media_type};base64,{image_data}"}, | ||
}, | ||
{"type": "text", "text": "What's the red curve in the figure, is it log2 or log10? Be concise."}, | ||
], | ||
} | ||
], | ||
stream=True, | ||
) | ||
for chunk in resp: | ||
if chunk.choices[0].delta.content: | ||
print(chunk.choices[0].delta.content, end="", flush=True) | ||
|
||
|
||
asyncio.run(completion()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import base64 | ||
|
||
import httpx | ||
import litellm | ||
|
||
from log10.litellm import Log10LitellmLogger | ||
|
||
|
||
log10_handler = Log10LitellmLogger(tags=["litellm_image", "stream"]) | ||
litellm.callbacks = [log10_handler] | ||
|
||
image_url = "https://upload.wikimedia.org/wikipedia/commons/e/e8/Log10.png" | ||
image_media_type = "image/png" | ||
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8") | ||
|
||
model_name = "claude-3-haiku-20240307" | ||
resp = litellm.completion( | ||
model=model_name, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{ | ||
"type": "image_url", | ||
"image_url": {"url": f"data:{image_media_type};base64,{image_data}"}, | ||
}, | ||
{"type": "text", "text": "What's the red curve in the figure, is it log2 or log10? Be concise."}, | ||
], | ||
} | ||
], | ||
stream=True, | ||
) | ||
for chunk in resp: | ||
if chunk.choices[0].delta.content: | ||
print(chunk.choices[0].delta.content, end="", flush=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import mistralai | ||
from mistralai.client import MistralClient | ||
from mistralai.models.chat_completion import ChatMessage | ||
|
||
from log10.load import log10 | ||
|
||
|
||
log10(mistralai) | ||
|
||
|
||
def main(): | ||
model = "mistral-tiny" | ||
|
||
client = MistralClient() | ||
|
||
chat_response = client.chat( | ||
model=model, | ||
messages=[ChatMessage(role="user", content="10 + 2 * 3=?")], | ||
) | ||
print(chat_response.choices[0].message.content) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import mistralai | ||
from mistralai.client import MistralClient | ||
from mistralai.models.chat_completion import ChatMessage | ||
|
||
from log10.load import log10 | ||
|
||
|
||
log10(mistralai) | ||
|
||
|
||
def main(): | ||
model = "mistral-tiny" | ||
|
||
client = MistralClient() | ||
|
||
response = client.chat_stream( | ||
model=model, | ||
messages=[ChatMessage(role="user", content="count the odd numbers from 1 to 20.")], | ||
) | ||
# import ipdb; ipdb.set_trace() | ||
for chunk in response: | ||
if chunk.choices[0].delta.content is not None: | ||
print(chunk.choices[0].delta.content, end="") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.