diff --git a/10-ai-framework-project b/10-ai-framework-project/README.md similarity index 100% rename from 10-ai-framework-project rename to 10-ai-framework-project/README.md diff --git a/10-ai-framework-project/code/python/app-chat.py b/10-ai-framework-project/code/python/app-chat.py new file mode 100644 index 00000000..160cfd81 --- /dev/null +++ b/10-ai-framework-project/code/python/app-chat.py @@ -0,0 +1,19 @@ +from langchain_core.messages import HumanMessage, SystemMessage +from langchain_openai import ChatOpenAI +import os + +llm = ChatOpenAI( + api_key=os.environ["GITHUB_TOKEN"], + base_url="https://models.github.ai/inference", + model="openai/gpt-4o-mini", +) + +messages = [ + SystemMessage(content="Translate the following from English into Italian"), + HumanMessage(content="hi!"), +] + + +# works +response = llm.invoke(messages) +print(response.content) \ No newline at end of file diff --git a/10-ai-framework-project/code/python/app-tools.py b/10-ai-framework-project/code/python/app-tools.py new file mode 100644 index 00000000..765fa26d --- /dev/null +++ b/10-ai-framework-project/code/python/app-tools.py @@ -0,0 +1,33 @@ +from langchain_core.messages import HumanMessage, SystemMessage +from langchain_openai import ChatOpenAI +import os +from typing_extensions import Annotated, TypedDict + +class add(TypedDict): + """Add two integers.""" + + # Annotations must have the type and can optionally include a default value and description (in that order). + a: Annotated[int, ..., "First integer"] + b: Annotated[int, ..., "Second integer"] + +tools = [add] + +functions = { + "add": lambda a, b: a + b +} + +llm = ChatOpenAI( + api_key=os.environ["GITHUB_TOKEN"], + base_url="https://models.github.ai/inference", + model="openai/gpt-4o-mini", +) + +llm_with_tools = llm.bind_tools(tools) + +query = "What is 3 + 12?" + +res = llm_with_tools.invoke(query) +if(res.tool_calls): + for tool in res.tool_calls: + print("TOOL CALL: ", functions[tool["name"]](**tool["args"])) +print("CONTENT: ",res.content) \ No newline at end of file diff --git a/10-ai-framework-project/code/python/app.py b/10-ai-framework-project/code/python/app.py new file mode 100644 index 00000000..4a4f9822 --- /dev/null +++ b/10-ai-framework-project/code/python/app.py @@ -0,0 +1,14 @@ +# pip install -qU "langchain[openai]" + +from langchain_openai import ChatOpenAI +import os + +llm = ChatOpenAI( + api_key=os.environ["GITHUB_TOKEN"], + base_url="https://models.github.ai/inference", + model="openai/gpt-4o-mini", +) + +# works +response = llm.invoke("What is 13 raised to the .3432 power?") +print(response.content) \ No newline at end of file diff --git a/10-ai-framework-project/solution/README.md b/10-ai-framework-project/solution/README.md new file mode 100644 index 00000000..e69de29b