Advertisement
Guest User

llm-python-file.py

a guest
Sep 18th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #!/bin/python3
  2.  
  3. import sys
  4. from openai import OpenAI
  5.  
  6. document_file_path = sys.argv[1]
  7. system = sys.argv[2]
  8. preprompt = sys.argv[3]
  9. postprompt = sys.argv[4]
  10. temp = sys.argv[5]
  11. # Read the content of the document file
  12. try:
  13.     with open(document_file_path, 'r') as file:
  14.         document = file.read()
  15. except FileNotFoundError:
  16.     print(f"Error: The file '{document_file_path}' does not exist.")
  17.     sys.exit(1)
  18. except Exception as e:
  19.     print(f"Error: {e}")
  20.     sys.exit(1)
  21.  
  22.  
  23. # Point to the local server
  24. client = OpenAI(base_url="http://localhost:9090/v1", api_key="lm-studio")
  25.  
  26. completion = client.chat.completions.create(
  27.   model="lmstudio-community/gemma-2-2b-it-q8_0",
  28.   messages=[
  29.     {"role": "system", "content": system },
  30.     {"role": "user", "content": preprompt },
  31.     {"role": "user", "content": document },
  32.     {"role": "user", "content": postprompt }
  33.   ],
  34.   temperature=temp,
  35. )
  36.  
  37. print(completion.choices[0].message.content.strip())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement