Spaces:
Sleeping
Sleeping
Download server/src/nodes/interview_nodes.py from VashuTheGreat2/ML-Learner: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/spaces/VashuTheGreat2/ML-Learner/resolve/main/server/src/nodes/interview_nodes.py
- Command line
-
hf download hf://spaces/VashuTheGreat2/ML-Learner/server/src/nodes/interview_nodes.py
-
curl -L -o interview_nodes.py https://huggingface.co/spaces/VashuTheGreat2/ML-Learner/resolve/main/server/src/nodes/interview_nodes.py
2.13 kB
| import logging | |
| from langsmith import traceable | |
| from langchain_core.messages import AIMessage, SystemMessage | |
| from src.utils.asyncHandler import asyncHandler | |
| from src.models.interview_model import InterviewState, Performance | |
| from src.prompts import QuestionGeneraterPrompt, interview_prompts2, generateInterviewPerformance_prompts | |
| from src.llm.llm_loader import llm | |
| from src.tools.taivily_search_tool import tavily_search | |
| tools = [tavily_search] | |
| async def generate_questions(state: InterviewState): | |
| if state.questions_generated and state.questions: | |
| return {} | |
| prompt = QuestionGeneraterPrompt.format(topic=state.topic) | |
| llm_with_tools = llm.bind_tools(tools=tools) | |
| res = await llm_with_tools.ainvoke(prompt) | |
| return { | |
| "questions_generated": True, | |
| "questions": res.content | |
| } | |
| async def performance_generation_node(state: InterviewState): | |
| prompt = generateInterviewPerformance_prompts.format() | |
| llm_structured = llm.with_structured_output(Performance) | |
| res = await llm_structured.ainvoke([prompt,*state.messages]) | |
| logging.info(res) | |
| return {"performance": res} | |
| async def chat(state: InterviewState): | |
| messages = state.messages | |
| if state.time_remaining <= 0: | |
| return { | |
| "messages": messages + [ | |
| AIMessage(content="⏰ Time's up! The interview has ended. Thank you for participating.") | |
| ] | |
| } | |
| system_instruction = ( | |
| f"{interview_prompts2.format(time_remaining=state.time_remaining)}\n\n" | |
| f"Interview Topic: {state.topic}\n" | |
| f"10 Generated Questions:\n{state.questions}" | |
| ) | |
| response = await llm.ainvoke( | |
| [SystemMessage(content=system_instruction)] + state.messages, | |
| config={"tags": ["chat_token"]} | |
| ) | |
| return { | |
| "messages": messages + [AIMessage(content=response.content)] | |
| } | |