Skip to content

Commit

Permalink
add llm
Browse files Browse the repository at this point in the history
  • Loading branch information
erexer committed Jan 14, 2025
1 parent 687a61a commit dedffde
Show file tree
Hide file tree
Showing 4 changed files with 496 additions and 3 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Dependencies
run: pip install -r requirements.txt

- name: Run Python Code
run: |
echo 'print("It works!")' > script.py
python script.py
env:
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
run: python format_file.py

43 changes: 43 additions & 0 deletions format_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os

from langchain_openai import AzureChatOpenAI
from langchain_core.prompts import ChatPromptTemplate


try:
# This code will raise a NameError because 'my_variable' is not defined
os.environ["AZURE_OPENAI_API_KEY"]
except Error as e:
# This block will execute if an Error occurs
print(f"No AZURE_OPENAI_API_KEY environment variable was found: {e}")

llm = AzureChatOpenAI(
azure_deployment="gpt-4o",
api_version="2024-02-01",
temperature=0.7,
max_tokens=250,
timeout=None,
max_retries=2,
# other params...
)

prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a friendly {language} expert performing a code review to provide helpful feedback to the programmer.",
),
("human", "{input}"),
]
)

chain = prompt | llm
chain.invoke(
{
"language": "Python",
"input": "Go through all the scripts in this repository and provide detailed feedback and suggestions on how to make the scripts easier to read, cleaner, and more reproducible.",
}
)

print(chain)
print(chain.content)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
langchain_openai==0.3.0
langchain_core==0.3.29
Loading

0 comments on commit dedffde

Please sign in to comment.