rashid01 commited on
Commit
3d3fec8
·
verified ·
1 Parent(s): e1af3d7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain import LLMChain, PromptTemplate
2
+ from langchain_gemini import ChatGoogleGenerativeAI # Adjusted import for Gemini
3
+ from langsmith import LangSmithClient
4
+ from langsmith.tracker import Tracker
5
+
6
+ # Initialize LangSmith Client
7
+ client = LangSmithClient(api_key='YOUR_LANGSMITH_API_KEY')
8
+ tracker = Tracker(client=client)
9
+
10
+ # Define a simple prompt template
11
+ prompt_template = PromptTemplate(
12
+ input_variables=['name'],
13
+ template='Hello {name}, how can I assist you today?'
14
+ )
15
+
16
+ # Initialize the Gemini AI LLM
17
+ gemini_ai = ChatGoogleGenerativeAI(api_key='YOUR_GEMINI_API_KEY') # Use your Gemini API key
18
+
19
+ # Create an LLMChain using the prompt template and Gemini AI LLM
20
+ llm_chain = LLMChain(
21
+ prompt=prompt_template,
22
+ llm=gemini_ai
23
+ )
24
+
25
+ # Define a function to use the LLMChain and track its usage
26
+ def generate_response(name):
27
+ # Track the request
28
+ tracker.track_event('LLM Request', {'name': name})
29
+
30
+ # Generate response using the LLMChain
31
+ response = llm_chain.run(name=name)
32
+
33
+ # Track the response
34
+ tracker.track_event('LLM Response', {'response': response})
35
+
36
+ return response
37
+
38
+ # Example usage
39
+ if __name__ == "__main__":
40
+ name = "Alice"
41
+ response = generate_response(name)
42
+ print(f"Generated Response: {response}")