User Tools

Site Tools


язык_программирования_python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
язык_программирования_python [2026/10/09 18:01]
val [request_to_my_ollama.py]
язык_программирования_python [2026/10/10 12:07] (current)
val [request_to_llm.py]
Line 500: Line 500:
  
 ==== request_to_my_ollama.py ==== ==== request_to_my_ollama.py ====
 +
 +  * самый простой пример для желающих
  
 <​code>​ <​code>​
Line 542: Line 544:
     sdk = AIStudio(     sdk = AIStudio(
         folder_id=os.getenv("​YANDEX_FOLDER_ID"​),​         folder_id=os.getenv("​YANDEX_FOLDER_ID"​),​
-        auth=os.getenv("​YANDEX_API_KEY")+        auth=os.getenv("​API_KEY")
     )     )
     messages = [{"​role":​ "​system",​ "​text":​ system_prompt}]     messages = [{"​role":​ "​system",​ "​text":​ system_prompt}]
Line 589: Line 591:
 <​code>​ <​code>​
 $ pip install openai $ pip install openai
 +  или
 +# apt install python3-openai
  
 export BASE_URL=http://​val.bmstu.ru:​8080/​v1 export BASE_URL=http://​val.bmstu.ru:​8080/​v1
Line 631: Line 635:
 if __name__ == "​__main__":​ if __name__ == "​__main__":​
  
-    system_prompt = ( +# Можно взять из request_to_llm.py 
-        "Ты — ассистент.\n" +#   ​или  
-        "​Отвечай кратко.\n" +# system_prompt ​в 1-м агрументе,​ user_request в stdin, chat_context пустой 
-    ​)+ 
 +    ​system_prompt = sys.argv[1]
  
     chat_context = []     chat_context = []
  
-    ​while True: +    ​print("​Введите ​запрос, ​для завершения ​нажмите Ctrl+D:", file=sys.stderr) 
-        try: +    ​user_request ​= sys.stdin.read()
-            user_request = input("​Введите ​ваш вопрос: ") +
-        except (KeyboardInterrupt, EOFError):​ +
-            print("​\nСессия завершена!") +
-            ​sys.exit(0) +
- +
-        reply_text ​= request_to_llm(user_request,​ system_prompt,​ chat_context) +
-        print(reply_text)+
  
-        chat_context.append({"​role":​ "​user",​ "​content": ​user_request}) +    reply_text = request_to_llm(user_request, system_prompt,​ chat_context) 
-        ​chat_context.append({"​role":​ "​assistant",​ "​content": ​reply_text})+    print(reply_text)
 </​code>​ </​code>​
  
язык_программирования_python.1791558099.txt.gz · Last modified: 2026/10/09 18:01 by val