Skip to content

Commit

Permalink
v0.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
MadcowD committed Oct 12, 2024
1 parent ed6f21a commit e7e7b3d
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 91 deletions.
57 changes: 0 additions & 57 deletions examples/bedrock_hello.py

This file was deleted.

4 changes: 2 additions & 2 deletions examples/future/limbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
ell.init(verbose=True, store='./logdir', autocommit=True)


@ell.tool(autogenerate=True)
def order_t_shirt(size, color, address):
@ell.tool()
def order_t_shirt(size : str, color : str, address : str):

# ....\
pass
Expand Down
19 changes: 9 additions & 10 deletions examples/openai_audio.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import ell
# import ell


ell.init(verbose=True)
# # ell.init(verbose=True)

@ell.complex("gpt-4o-audio-preview")
def test():
return [ell.user("Hey! Could you talk to me in spanish? I'd like to hear how you say 'ell'.")]
# # @ell.complex("gpt-4o-audio-preview")
# # def test():
# # return [ell.user("Hey! Could you talk to me in spanish? I'd like to hear how you say 'ell'.")]

response = test()
print(response.audios[0])

if __name__ == "__main__":
test()
if __name__ == "__main__":
# # response = test()
# # print(response.audios[0])
pass

3 changes: 3 additions & 0 deletions examples/openai_prompt_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def cached_chat(history : List[str], new_message : str) -> str:



if __name__ == "__main__":
pass




Expand Down
1 change: 1 addition & 0 deletions examples/providers/xai_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ell.init(verbose=True)

# Models are automatically registered, so we can use them without specifying the client
# set XAI_API_KEY=your_api_key in your environment to run this example
@ell.simple(model='grok-2-mini')
def use_default_xai_client(prompt: str) -> str:
return prompt
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ell-ai"
version = "0.0.13"
version = "0.0.14"
description = "ell - the language model programming library"
authors = ["William Guss <will@lrsys.xyz>"]
license = "MIT"
Expand Down Expand Up @@ -41,6 +41,7 @@ requests = "^2.32.3"
typing-extensions = "^4.12.2"
black = "^24.8.0"
pillow = "^10.4.0"
psutil = "^5.9.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.2"
Expand Down
7 changes: 6 additions & 1 deletion src/ell/models/xai.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ def register(client: openai.Client):
for model_id in standard_models:
config.register_model(model_id, client)


default_client = None
try:
default_client = openai.Client(base_url="https://api.x.ai/v1", api_key=os.environ.get("XAI_API_KEY"))

xai_api_key = os.environ.get("XAI_API_KEY")
if not xai_api_key:
raise openai.OpenAIError("XAI_API_KEY not found in environment variables")
default_client = openai.Client(base_url="https://api.x.ai/v1", api_key=xai_api_key)
except openai.OpenAIError as e:
pass

Expand Down
9 changes: 8 additions & 1 deletion tests/.exampleignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ webcam_activity_describer.py
openaigym.py
o1.py
chord*
server_example.py
server_example.py
limbo.py
providers/bedrock_ex.py
azure_ex.py
openrouter_ex.py
vllm_ex.py
*_ex.py
bedrock_hello.py
60 changes: 41 additions & 19 deletions tests/run_all_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import subprocess
import sys
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
from concurrent.futures import ThreadPoolExecutor, as_completed, TimeoutError
import logging
from colorama import Fore, Style, init
from colorama import Fore, Style, init # type: ignore
import argparse
import json
import hashlib
import fnmatch
import threading
import psutil

# Initialize colorama for cross-platform colored output
init()
Expand Down Expand Up @@ -63,20 +64,35 @@ def run_example(example_path, verbose=False, cache=None):
# Prepare simulated input based on the example file
simulated_input = get_simulated_input(filename)

# Run the example with simulated input
process = subprocess.Popen(
[sys.executable, example_path],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)

stdout, stderr = process.communicate(input=simulated_input)


def kill_proc_tree(pid):
parent = psutil.Process(pid)
for child in parent.children(recursive=True):
child.kill()
parent.kill()

try:
stdout, stderr = process.communicate(input=simulated_input, timeout=60)
except subprocess.TimeoutExpired:
kill_proc_tree(process.pid)
return filename, "TIMEOUT", 60, "Example execution timed out after 60 seconds", ""

end_time = time.time()
runtime = end_time - start_time

if process.returncode != 0:
error_message = f"Process exited with non-zero status: {process.returncode}\nStderr: {stderr}"
if cache is not None:
update_cache(cache, file_hash, "ERROR", runtime)
return filename, "ERROR", runtime, error_message, stdout

if cache is not None:
update_cache(cache, file_hash, "SUCCESS", runtime)
return filename, "SUCCESS", runtime, None, stdout
Expand Down Expand Up @@ -146,18 +162,21 @@ def run_all_examples(args):
print(f"{Fore.GREEN}{futures[future]} . (Runtime: {runtime:.2f}s){Style.RESET_ALL}")
elif status == "CACHED":
print(f"{Fore.BLUE}{futures[future]} C (Cached Runtime: {runtime:.2f}s){Style.RESET_ALL}")
elif status == "TIMEOUT":
print(f"{Fore.YELLOW}{futures[future]} T (Timeout: {runtime:.2f}s){Style.RESET_ALL}")
print(f" Error: {error}")
else:
print(f"{Fore.RED}{futures[future]} F (Runtime: {runtime:.2f}s){Style.RESET_ALL}")
print(f" Error: {error}")
print(f" Full output:")
print(output)
if not args.continue_on_error:
print(f"\n{Fore.RED}Stopping execution due to failure.{Style.RESET_ALL}")
for running_future in futures:
if not running_future.done():
print(f"{Fore.YELLOW}Cancelling: {futures[running_future]}{Style.RESET_ALL}")
executor.shutdown(wait=False, cancel_futures=True)
break
if status in ["ERROR", "TIMEOUT"] and not args.continue_on_error:
print(f"\n{Fore.RED}Stopping execution due to failure.{Style.RESET_ALL}")
for running_future in futures:
if not running_future.done():
print(f"{Fore.YELLOW}Cancelling: {futures[running_future]}{Style.RESET_ALL}")
executor.shutdown(wait=False, cancel_futures=True)
break

if args.cache:
save_cache(cache)
Expand All @@ -166,18 +185,21 @@ def run_all_examples(args):
total_examples = len(results)
successful = sum(1 for _, status, _, _ in results if status in {"SUCCESS", "CACHED"})
failed = sum(1 for _, status, _, _ in results if status == "ERROR")
skipped = total_examples - successful - failed
timed_out = sum(1 for _, status, _, _ in results if status == "TIMEOUT")
skipped = total_examples - successful - failed - timed_out

print(f"Total examples: {total_examples}")
print(f"{Fore.GREEN}Successful: {successful}{Style.RESET_ALL}")
print(f"{Fore.RED}Failed: {failed}{Style.RESET_ALL}")
print(f"{Fore.YELLOW}Timed out: {timed_out}{Style.RESET_ALL}")
print(f"{Fore.YELLOW}Skipped: {skipped}{Style.RESET_ALL}")

if failed > 0:
print("\nFailed examples:")
if failed > 0 or timed_out > 0:
print("\nFailed or timed out examples:")
for example, status, runtime, error in results:
if status == "ERROR":
print(f"{Fore.RED}{example} (Runtime: {runtime:.2f}s){Style.RESET_ALL}")
if status in ["ERROR", "TIMEOUT"]:
color = Fore.RED if status == "ERROR" else Fore.YELLOW
print(f"{color}{example} ({status}, Runtime: {runtime:.2f}s){Style.RESET_ALL}")
print(f" Error: {error}")

average_runtime = sum(runtime for _, _, runtime, _ in results) / len(results)
Expand All @@ -186,7 +208,7 @@ def run_all_examples(args):
if all(status in {"SUCCESS", "CACHED"} for _, status, _, _ in results):
print(f"\n{Fore.GREEN}All examples were successful.{Style.RESET_ALL}")
else:
print(f"\n{Fore.YELLOW}Some examples did not run successfully. Please review the output above.{Style.RESET_ALL}")
print(f"\n{Fore.YELLOW}Some examples did not run successfully or timed out. Please review the output above.{Style.RESET_ALL}")

if __name__ == "__main__":
args = parse_arguments()
Expand Down

0 comments on commit e7e7b3d

Please sign in to comment.