microeval 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
microeval/__init__.py ADDED
File without changes
microeval/chat.py ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Interactive chat loop with LLM providers.
4
+ """
5
+
6
+ import asyncio
7
+ import json
8
+ from pathlib import Path
9
+
10
+ from dotenv import load_dotenv
11
+
12
+ from microeval.chat_client import get_chat_client
13
+
14
+ load_dotenv()
15
+
16
+ config_path = Path(__file__).parent / "config.json"
17
+ with open(config_path) as f:
18
+ config = json.load(f)
19
+ chat_models = config["chat_models"]
20
+
21
+
22
+ async def setup_async_exception_handler():
23
+ loop = asyncio.get_event_loop()
24
+
25
+ def silence_event_loop_closed(loop, context):
26
+ if "exception" not in context or not isinstance(
27
+ context["exception"], (RuntimeError, GeneratorExit)
28
+ ):
29
+ loop.default_exception_handler(context)
30
+
31
+ loop.set_exception_handler(silence_event_loop_closed)
32
+
33
+
34
+ async def amain(service):
35
+ await setup_async_exception_handler()
36
+ async with get_chat_client(service, model=chat_models[service]) as client:
37
+ print(f"Chat loop with {service}-{client.model}")
38
+ conversation_history = []
39
+ while True:
40
+ user_input = input("\nYou: ")
41
+ if user_input.lower() in ["quit", "exit"]:
42
+ print("Goodbye!")
43
+ break
44
+ conversation_history.append({"role": "user", "content": user_input})
45
+ messages = [{"role": "user", "content": user_input}]
46
+ result = await client.get_completion(messages)
47
+ response_text = result.get("text", "")
48
+ print(f"\nResponse: {response_text}")
49
+ conversation_history.append({"role": "assistant", "content": response_text})
50
+
51
+
52
+ def main(service: str = "openai"):
53
+ try:
54
+ asyncio.run(amain(service))
55
+ except KeyboardInterrupt:
56
+ print("\nGoodbye!")
57
+ except Exception as e:
58
+ print(f"\n\nUnexpected error: {e}")
59
+
60
+
61
+ if __name__ == "__main__":
62
+ main()