|
1 |
| -import httpx |
| 1 | +import requests |
| 2 | +import json |
2 | 3 | import os
|
3 |
| -import ssl |
| 4 | +from ilab_model import IlabLLM |
| 5 | +from dotenv import load_dotenv |
| 6 | +from langchain_core.prompts import PromptTemplate |
| 7 | +from langchain.chains import LLMChain |
| 8 | + |
| 9 | +load_dotenv() |
4 | 10 |
|
5 | 11 | # manage ENV
|
6 | 12 | model_endpoint=os.getenv('MODEL_ENDPOINT')
|
|
11 | 17 | if model_name == "":
|
12 | 18 | model_name = "ibm/merlinite-7b"
|
13 | 19 |
|
14 |
| -model_token=os.getenv('MODEL_TOKEN') |
| 20 | +model_token=os.getenv('ILAB_API_TOKEN') |
15 | 21 |
|
16 | 22 | # HTTPS client
|
17 |
| -client_key_path = "/home/fedora/client-tls-key.pem2" |
18 |
| -client_crt_path = "/home/fedora/client-tls-crt.pem2" |
19 |
| -server_ca_crt = "/home/fedora/server-ca-crt.pem2" |
20 |
| - |
21 |
| -ssl_context = ssl.create_default_context(cafile=server_ca_crt) |
22 |
| -ssl_context.load_cert_chain(certfile=client_crt_path, keyfile=client_key_path) |
23 |
| - |
24 |
| -client = httpx.Client(verify=ssl_context) |
25 |
| - |
26 |
| - |
27 |
| -def get_openai_response(prompt, **kwargs): |
28 |
| - url = model_endpoint |
29 |
| - headers = { |
30 |
| - "Authorization": f"Bearer {model_token}", |
31 |
| - "Content-Type": "application/json" |
32 |
| - } |
33 |
| - data = { |
34 |
| - "model": model_name, |
35 |
| - "max_tokens": 4096, |
36 |
| - "messages": [ |
37 |
| - { |
38 |
| - "role": "system", |
39 |
| - "content": "You are an AI language model developed by IBM Research. You are a cautious assistant that carefully follows instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior." |
40 |
| - }, |
41 |
| - { |
42 |
| - "role":"user", |
43 |
| - "content": prompt |
44 |
| - } |
45 |
| - ], |
46 |
| - "logprobs":False, |
47 |
| - "stream":False |
48 |
| - } |
49 |
| - |
50 |
| - response = client.post(url, json=data, headers=headers) |
51 |
| - response.raise_for_status() |
52 |
| - return response.json() |
53 |
| - |
54 |
| -question = """ Question: I am training for an upcoming marathon but I am completely out of shape! Can you help me to implement a plan to prepare me for running a marathon in 12 weeks? |
55 |
| -
|
56 |
| -Answer: Let's think step by step. """ |
57 |
| - |
58 |
| -# get_openai_response(question) |
| 23 | +# client_key_path = "/home/fedora/client-tls-key.pem2" |
| 24 | +# client_crt_path = "/home/fedora/client-tls-crt.pem2" |
| 25 | +# server_ca_crt = "/home/fedora/server-ca-crt.pem2" |
| 26 | + |
| 27 | +# ssl_context = ssl.create_default_context(cafile=server_ca_crt) |
| 28 | +# ssl_context.load_cert_chain(certfile=client_crt_path, keyfile=client_key_path) |
| 29 | + |
| 30 | +# client = httpx.Client(verify=ssl_context) |
| 31 | + |
| 32 | +# data = { |
| 33 | +# "model": "instructlab/granite-7b-lab", |
| 34 | +# "messages": [ |
| 35 | +# {"role": "system", "content": "your name is carl"}, |
| 36 | +# {"role": "user", "content": "what is your name?"} |
| 37 | +# ], |
| 38 | +# "temperature": 1, |
| 39 | +# "max_tokens": 1792, |
| 40 | +# "top_p": 1, |
| 41 | +# "repetition_penalty": 1.05, |
| 42 | +# "stop": ["<|endoftext|>"], |
| 43 | +# "logprobs": False, |
| 44 | +# "stream": False |
| 45 | +# } |
| 46 | + |
| 47 | +# response = requests.post(url, headers=headers, data=json.dumps(data), verify=False) |
| 48 | +# print(response.json()) |
| 49 | +print(f'model_name={model_name}') |
| 50 | +llm = IlabLLM( |
| 51 | + model_endpoint=model_endpoint, |
| 52 | + model_name=model_name, |
| 53 | + apikey=model_token, |
| 54 | + temperature=1, |
| 55 | + max_tokens=500, |
| 56 | + top_p=1, |
| 57 | + repetition_penalty=1.05, |
| 58 | + stop=["<|endoftext|>"], |
| 59 | + streaming=False |
| 60 | +) |
| 61 | + |
| 62 | +prompt="I am training for a marathon in 12 weeks. Can you help me build an exercise plan to help prepare myself?" |
| 63 | +prompts=[prompt] |
| 64 | +# prompt_template = PromptTemplate.from_template(prompt) |
| 65 | +llm.generate(prompts) |
| 66 | +# llm.invoke("dog") |
0 commit comments