Victorano commited on
Commit
539ee6f
1 Parent(s): 118335a

Gradio App for Llama-3.2-1B-it fine tuned as a ecommerce customer support

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ llama-3.2-1B-it-Ecommerce-ChatBot-merged-F16.gguf filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from model import llm
3
+
4
+
5
+ def generate_response(message: str, history) -> str:
6
+ return llm.create_chat_completion(
7
+ messages=[
8
+ {
9
+ "role": "system",
10
+ "content": "You are a top-rated customer service agent named John. Be polite to customers and answer all their questions. If the question is out of context and not related to your job as a customer service agent, let the customer know that you can not help and they should look elsewhere for answers."
11
+ },
12
+ {
13
+ "role": "user",
14
+ "content": message
15
+ }
16
+ ]
17
+ )['choices'][0]['message']['content']
18
+
19
+
20
+ demo = gr.ChatInterface(
21
+ fn=generate_response,
22
+ examples=[
23
+ "What Payment Modalities are accepted?",
24
+ "Can you help me cancel an order?",
25
+ "What is your name and how can you help me today?"
26
+ ],
27
+ title="Customer Support",
28
+ description="""This is the further fine tuned version of meta-llama/Llama-3.2-1B-Instruct.
29
+ Fine tuned on the https://huggingface.co/datasets/bitext/Bitext-customer-support-llm-chatbot-training-dataset dataset. Random seed of 65 was used to select 1k rows from the dataset, find that version at https://huggingface.co/datasets/Victorano/customer-support-1k, all on huggingface.
30
+ You can find the full source code at (https://github.com/Victoran0/ECommerce-customer-support-chatbot).""",
31
+ theme="HaleyCH/HaleyCH_Theme"
32
+ )
33
+
34
+ demo.launch()
llama-3.2-1B-it-Ecommerce-ChatBot-merged-F16.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbf841ee444836d5055e72d081b145ff90f41df2e86f72713a643c2c6cc2917e
3
+ size 2479595008
model.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llama_cpp import Llama
2
+ import os
3
+
4
+ model_path = "llama-3.2-1B-it-Ecommerce-ChatBot-merged-F16.gguf"
5
+ n_threads = os.cpu_count()
6
+
7
+ llm = Llama(
8
+ model_path=model_path,
9
+ n_ctx=512,
10
+ n_batch=32,
11
+ n_threads=n_threads,
12
+ n_gpu_layers=-1,
13
+ chat_format="llama-3"
14
+ )
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ llama-cpp-python==0.3.1
2
+ gradio==4.44.0
researcn.ipynb ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 50,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "# from unsloth import FastLanguageModel\n",
10
+ "from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig\n",
11
+ "import torch\n",
12
+ "from llama_cpp import Llama\n",
13
+ "from pathlib import Path\n",
14
+ "import gradio as gr\n",
15
+ "from peft import PeftModelForCausalLM, PeftConfig"
16
+ ]
17
+ },
18
+ {
19
+ "cell_type": "code",
20
+ "execution_count": null,
21
+ "metadata": {},
22
+ "outputs": [],
23
+ "source": [
24
+ "\"C:/Users/User/Data Science/Deep Learning/Generative AI/Fine Tuning LLMs/ECommerce-customer-support-chatbot/model_init/llama-3.2-1B-it-Ecommerce-ChatBot-merged-F16.gguf\""
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 66,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "model_id = \"llama-3.2-1B-it-Ecommerce-ChatBot-merged-F16.gguf\""
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 57,
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "model_path = \"C:/Users/User/Data Science/Deep Learning/Generative AI/Fine Tuning LLMs/fine-tuning llama 3.2 1B/trainerdotsavemodel\""
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": 63,
48
+ "metadata": {},
49
+ "outputs": [
50
+ {
51
+ "data": {
52
+ "text/plain": [
53
+ "8"
54
+ ]
55
+ },
56
+ "execution_count": 63,
57
+ "metadata": {},
58
+ "output_type": "execute_result"
59
+ }
60
+ ],
61
+ "source": [
62
+ "import os\n",
63
+ "os.cpu_count()"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 77,
69
+ "metadata": {},
70
+ "outputs": [
71
+ {
72
+ "name": "stderr",
73
+ "output_type": "stream",
74
+ "text": [
75
+ "llama_model_loader: loaded meta data with 26 key-value pairs and 147 tensors from llama-3.2-1B-it-Ecommerce-ChatBot-merged-F16.gguf (version GGUF V3 (latest))\n",
76
+ "llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.\n",
77
+ "llama_model_loader: - kv 0: general.architecture str = llama\n",
78
+ "llama_model_loader: - kv 1: general.type str = model\n",
79
+ "llama_model_loader: - kv 2: general.name str = E9F8Effbab1Cbdc515C11Ee6E098E3D5A9F51E14\n",
80
+ "llama_model_loader: - kv 3: general.size_label str = 1.2B\n",
81
+ "llama_model_loader: - kv 4: llama.block_count u32 = 16\n",
82
+ "llama_model_loader: - kv 5: llama.context_length u32 = 131072\n",
83
+ "llama_model_loader: - kv 6: llama.embedding_length u32 = 2048\n",
84
+ "llama_model_loader: - kv 7: llama.feed_forward_length u32 = 8192\n",
85
+ "llama_model_loader: - kv 8: llama.attention.head_count u32 = 32\n",
86
+ "llama_model_loader: - kv 9: llama.attention.head_count_kv u32 = 8\n",
87
+ "llama_model_loader: - kv 10: llama.rope.freq_base f32 = 500000.000000\n",
88
+ "llama_model_loader: - kv 11: llama.attention.layer_norm_rms_epsilon f32 = 0.000010\n",
89
+ "llama_model_loader: - kv 12: llama.attention.key_length u32 = 64\n",
90
+ "llama_model_loader: - kv 13: llama.attention.value_length u32 = 64\n",
91
+ "llama_model_loader: - kv 14: general.file_type u32 = 1\n",
92
+ "llama_model_loader: - kv 15: llama.vocab_size u32 = 128256\n",
93
+ "llama_model_loader: - kv 16: llama.rope.dimension_count u32 = 64\n",
94
+ "llama_model_loader: - kv 17: tokenizer.ggml.model str = gpt2\n",
95
+ "llama_model_loader: - kv 18: tokenizer.ggml.pre str = llama-bpe\n",
96
+ "llama_model_loader: - kv 19: tokenizer.ggml.tokens arr[str,128256] = [\"!\", \"\\\"\", \"#\", \"$\", \"%\", \"&\", \"'\", ...\n",
97
+ "llama_model_loader: - kv 20: tokenizer.ggml.token_type arr[i32,128256] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\n",
98
+ "llama_model_loader: - kv 21: tokenizer.ggml.merges arr[str,280147] = [\"Ġ Ġ\", \"Ġ ĠĠĠ\", \"ĠĠ ĠĠ\", \"...\n",
99
+ "llama_model_loader: - kv 22: tokenizer.ggml.bos_token_id u32 = 128000\n",
100
+ "llama_model_loader: - kv 23: tokenizer.ggml.eos_token_id u32 = 128009\n",
101
+ "llama_model_loader: - kv 24: tokenizer.chat_template str = {{- bos_token }}\\n{%- if custom_tools ...\n",
102
+ "llama_model_loader: - kv 25: general.quantization_version u32 = 2\n",
103
+ "llama_model_loader: - type f32: 34 tensors\n",
104
+ "llama_model_loader: - type f16: 113 tensors\n",
105
+ "llm_load_vocab: special tokens cache size = 256\n",
106
+ "llm_load_vocab: token to piece cache size = 0.7999 MB\n",
107
+ "llm_load_print_meta: format = GGUF V3 (latest)\n",
108
+ "llm_load_print_meta: arch = llama\n",
109
+ "llm_load_print_meta: vocab type = BPE\n",
110
+ "llm_load_print_meta: n_vocab = 128256\n",
111
+ "llm_load_print_meta: n_merges = 280147\n",
112
+ "llm_load_print_meta: vocab_only = 0\n",
113
+ "llm_load_print_meta: n_ctx_train = 131072\n",
114
+ "llm_load_print_meta: n_embd = 2048\n",
115
+ "llm_load_print_meta: n_layer = 16\n",
116
+ "llm_load_print_meta: n_head = 32\n",
117
+ "llm_load_print_meta: n_head_kv = 8\n",
118
+ "llm_load_print_meta: n_rot = 64\n",
119
+ "llm_load_print_meta: n_swa = 0\n",
120
+ "llm_load_print_meta: n_embd_head_k = 64\n",
121
+ "llm_load_print_meta: n_embd_head_v = 64\n",
122
+ "llm_load_print_meta: n_gqa = 4\n",
123
+ "llm_load_print_meta: n_embd_k_gqa = 512\n",
124
+ "llm_load_print_meta: n_embd_v_gqa = 512\n",
125
+ "llm_load_print_meta: f_norm_eps = 0.0e+00\n",
126
+ "llm_load_print_meta: f_norm_rms_eps = 1.0e-05\n",
127
+ "llm_load_print_meta: f_clamp_kqv = 0.0e+00\n",
128
+ "llm_load_print_meta: f_max_alibi_bias = 0.0e+00\n",
129
+ "llm_load_print_meta: f_logit_scale = 0.0e+00\n",
130
+ "llm_load_print_meta: n_ff = 8192\n",
131
+ "llm_load_print_meta: n_expert = 0\n",
132
+ "llm_load_print_meta: n_expert_used = 0\n",
133
+ "llm_load_print_meta: causal attn = 1\n",
134
+ "llm_load_print_meta: pooling type = 0\n",
135
+ "llm_load_print_meta: rope type = 0\n",
136
+ "llm_load_print_meta: rope scaling = linear\n",
137
+ "llm_load_print_meta: freq_base_train = 500000.0\n",
138
+ "llm_load_print_meta: freq_scale_train = 1\n",
139
+ "llm_load_print_meta: n_ctx_orig_yarn = 131072\n",
140
+ "llm_load_print_meta: rope_finetuned = unknown\n",
141
+ "llm_load_print_meta: ssm_d_conv = 0\n",
142
+ "llm_load_print_meta: ssm_d_inner = 0\n",
143
+ "llm_load_print_meta: ssm_d_state = 0\n",
144
+ "llm_load_print_meta: ssm_dt_rank = 0\n",
145
+ "llm_load_print_meta: ssm_dt_b_c_rms = 0\n",
146
+ "llm_load_print_meta: model type = ?B\n",
147
+ "llm_load_print_meta: model ftype = F16\n",
148
+ "llm_load_print_meta: model params = 1.24 B\n",
149
+ "llm_load_print_meta: model size = 2.30 GiB (16.00 BPW) \n",
150
+ "llm_load_print_meta: general.name = E9F8Effbab1Cbdc515C11Ee6E098E3D5A9F51E14\n",
151
+ "llm_load_print_meta: BOS token = 128000 '<|begin_of_text|>'\n",
152
+ "llm_load_print_meta: EOS token = 128009 '<|eot_id|>'\n",
153
+ "llm_load_print_meta: LF token = 128 'Ä'\n",
154
+ "llm_load_print_meta: EOT token = 128009 '<|eot_id|>'\n",
155
+ "llm_load_print_meta: EOM token = 128008 '<|eom_id|>'\n",
156
+ "llm_load_print_meta: EOG token = 128008 '<|eom_id|>'\n",
157
+ "llm_load_print_meta: EOG token = 128009 '<|eot_id|>'\n",
158
+ "llm_load_print_meta: max token length = 256\n",
159
+ "llm_load_tensors: ggml ctx size = 0.07 MiB\n",
160
+ "llm_load_tensors: CPU buffer size = 2357.26 MiB\n",
161
+ ".............................................................\n",
162
+ "llama_new_context_with_model: n_ctx = 512\n",
163
+ "llama_new_context_with_model: n_batch = 32\n",
164
+ "llama_new_context_with_model: n_ubatch = 32\n",
165
+ "llama_new_context_with_model: flash_attn = 0\n",
166
+ "llama_new_context_with_model: freq_base = 500000.0\n",
167
+ "llama_new_context_with_model: freq_scale = 1\n",
168
+ "llama_kv_cache_init: CPU KV buffer size = 16.00 MiB\n",
169
+ "llama_new_context_with_model: KV self size = 16.00 MiB, K (f16): 8.00 MiB, V (f16): 8.00 MiB\n",
170
+ "llama_new_context_with_model: CPU output buffer size = 0.49 MiB\n",
171
+ "llama_new_context_with_model: CPU compute buffer size = 15.91 MiB\n",
172
+ "llama_new_context_with_model: graph nodes = 518\n",
173
+ "llama_new_context_with_model: graph splits = 1\n",
174
+ "AVX = 1 | AVX_VNNI = 0 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | AVX512_BF16 = 0 | FMA = 1 | NEON = 0 | SVE = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | RISCV_VECT = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 1 | \n",
175
+ "Model metadata: {'general.name': 'E9F8Effbab1Cbdc515C11Ee6E098E3D5A9F51E14', 'general.architecture': 'llama', 'general.type': 'model', 'llama.feed_forward_length': '8192', 'general.size_label': '1.2B', 'llama.block_count': '16', 'llama.context_length': '131072', 'llama.embedding_length': '2048', 'llama.attention.head_count': '32', 'tokenizer.ggml.eos_token_id': '128009', 'general.file_type': '1', 'llama.attention.head_count_kv': '8', 'llama.rope.freq_base': '500000.000000', 'llama.attention.layer_norm_rms_epsilon': '0.000010', 'llama.attention.key_length': '64', 'llama.attention.value_length': '64', 'llama.vocab_size': '128256', 'llama.rope.dimension_count': '64', 'tokenizer.ggml.model': 'gpt2', 'tokenizer.ggml.pre': 'llama-bpe', 'general.quantization_version': '2', 'tokenizer.ggml.bos_token_id': '128000', 'tokenizer.chat_template': '{{- bos_token }}\\n{%- if custom_tools is defined %}\\n {%- set tools = custom_tools %}\\n{%- endif %}\\n{%- if not tools_in_user_message is defined %}\\n {%- set tools_in_user_message = true %}\\n{%- endif %}\\n{%- if not date_string is defined %}\\n {%- if strftime_now is defined %}\\n {%- set date_string = strftime_now(\"%d %b %Y\") %}\\n {%- else %}\\n {%- set date_string = \"26 Jul 2024\" %}\\n {%- endif %}\\n{%- endif %}\\n{%- if not tools is defined %}\\n {%- set tools = none %}\\n{%- endif %}\\n\\n{#- This block extracts the system message, so we can slot it into the right place. #}\\n{%- if messages[0][\\'role\\'] == \\'system\\' %}\\n {%- set system_message = messages[0][\\'content\\']|trim %}\\n {%- set messages = messages[1:] %}\\n{%- else %}\\n {%- set system_message = \"\" %}\\n{%- endif %}\\n\\n{#- System message #}\\n{{- \"<|start_header_id|>system<|end_header_id|>\\\\n\\\\n\" }}\\n{%- if tools is not none %}\\n {{- \"Environment: ipython\\\\n\" }}\\n{%- endif %}\\n{{- \"Cutting Knowledge Date: December 2023\\\\n\" }}\\n{{- \"Today Date: \" + date_string + \"\\\\n\\\\n\" }}\\n{%- if tools is not none and not tools_in_user_message %}\\n {{- \"You have access to the following functions. To call a function, please respond with JSON for a function call.\" }}\\n {{- \\'Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.\\' }}\\n {{- \"Do not use variables.\\\\n\\\\n\" }}\\n {%- for t in tools %}\\n {{- t | tojson(indent=4) }}\\n {{- \"\\\\n\\\\n\" }}\\n {%- endfor %}\\n{%- endif %}\\n{{- system_message }}\\n{{- \"<|eot_id|>\" }}\\n\\n{#- Custom tools are passed in a user message with some extra guidance #}\\n{%- if tools_in_user_message and not tools is none %}\\n {#- Extract the first user message so we can plug it in here #}\\n {%- if messages | length != 0 %}\\n {%- set first_user_message = messages[0][\\'content\\']|trim %}\\n {%- set messages = messages[1:] %}\\n {%- else %}\\n {{- raise_exception(\"Cannot put tools in the first user message when there\\'s no first user message!\") }}\\n{%- endif %}\\n {{- \\'<|start_header_id|>user<|end_header_id|>\\\\n\\\\n\\' -}}\\n {{- \"Given the following functions, please respond with a JSON for a function call \" }}\\n {{- \"with its proper arguments that best answers the given prompt.\\\\n\\\\n\" }}\\n {{- \\'Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.\\' }}\\n {{- \"Do not use variables.\\\\n\\\\n\" }}\\n {%- for t in tools %}\\n {{- t | tojson(indent=4) }}\\n {{- \"\\\\n\\\\n\" }}\\n {%- endfor %}\\n {{- first_user_message + \"<|eot_id|>\"}}\\n{%- endif %}\\n\\n{%- for message in messages %}\\n {%- if not (message.role == \\'ipython\\' or message.role == \\'tool\\' or \\'tool_calls\\' in message) %}\\n {{- \\'<|start_header_id|>\\' + message[\\'role\\'] + \\'<|end_header_id|>\\\\n\\\\n\\'+ message[\\'content\\'] | trim + \\'<|eot_id|>\\' }}\\n {%- elif \\'tool_calls\\' in message %}\\n {%- if not message.tool_calls|length == 1 %}\\n {{- raise_exception(\"This model only supports single tool-calls at once!\") }}\\n {%- endif %}\\n {%- set tool_call = message.tool_calls[0].function %}\\n {{- \\'<|start_header_id|>assistant<|end_header_id|>\\\\n\\\\n\\' -}}\\n {{- \\'{\"name\": \"\\' + tool_call.name + \\'\", \\' }}\\n {{- \\'\"parameters\": \\' }}\\n {{- tool_call.arguments | tojson }}\\n {{- \"}\" }}\\n {{- \"<|eot_id|>\" }}\\n {%- elif message.role == \"tool\" or message.role == \"ipython\" %}\\n {{- \"<|start_header_id|>ipython<|end_header_id|>\\\\n\\\\n\" }}\\n {%- if message.content is mapping or message.content is iterable %}\\n {{- message.content | tojson }}\\n {%- else %}\\n {{- message.content }}\\n {%- endif %}\\n {{- \"<|eot_id|>\" }}\\n {%- endif %}\\n{%- endfor %}\\n{%- if add_generation_prompt %}\\n {{- \\'<|start_header_id|>assistant<|end_header_id|>\\\\n\\\\n\\' }}\\n{%- endif %}\\n'}\n",
176
+ "Available chat formats from metadata: chat_template.default\n"
177
+ ]
178
+ }
179
+ ],
180
+ "source": [
181
+ "llm = Llama(model_path=model_id, n_ctx=512, n_batch=32, n_threads=os.cpu_count(), n_gpu_layers=-1, chat_format=\"llama-3\", verbose=True)"
182
+ ]
183
+ },
184
+ {
185
+ "cell_type": "code",
186
+ "execution_count": 15,
187
+ "metadata": {},
188
+ "outputs": [
189
+ {
190
+ "name": "stdout",
191
+ "output_type": "stream",
192
+ "text": [
193
+ "Certainly! I'm here to assist you with any concerns or questions you may have. Whether it's regarding your account, a product or service, or any other matter, I'm here to provide you with the guidance and support you need.\n"
194
+ ]
195
+ }
196
+ ],
197
+ "source": [
198
+ "print(response['choices'][0]['text'])"
199
+ ]
200
+ },
201
+ {
202
+ "cell_type": "code",
203
+ "execution_count": 72,
204
+ "metadata": {},
205
+ "outputs": [],
206
+ "source": [
207
+ "def generate_response(message:str) -> str:\n",
208
+ " return llm.create_chat_completion(\n",
209
+ " messages=[\n",
210
+ " {\n",
211
+ " \"role\": \"system\",\n",
212
+ " \"content\": \"You are a top-rated customer service agent named John. Be polite to customers and answer all their questions. If the question is out of context and not related to your job as a customer service agent, let the customer know that you can not help and they should look elsewhere for answers.\"\n",
213
+ " },\n",
214
+ " {\n",
215
+ " \"role\": \"user\",\n",
216
+ " \"content\": message\n",
217
+ " }\n",
218
+ " ]\n",
219
+ " )['choices'][0]['message']['content']"
220
+ ]
221
+ },
222
+ {
223
+ "cell_type": "code",
224
+ "execution_count": 78,
225
+ "metadata": {},
226
+ "outputs": [
227
+ {
228
+ "name": "stderr",
229
+ "output_type": "stream",
230
+ "text": [
231
+ "llama_perf_context_print: load time = 2383.18 ms\n",
232
+ "llama_perf_context_print: prompt eval time = 0.00 ms / 82 tokens ( 0.00 ms per token, inf tokens per second)\n",
233
+ "llama_perf_context_print: eval time = 0.00 ms / 71 runs ( 0.00 ms per token, inf tokens per second)\n",
234
+ "llama_perf_context_print: total time = 15843.08 ms / 153 tokens\n"
235
+ ]
236
+ },
237
+ {
238
+ "data": {
239
+ "text/plain": [
240
+ "'Your invoice for a particular order is located in your account on our website. To access it, simply log in to your account and navigate to the \"Invoices\" section. From there, you should be able to view your invoice in detail and take any necessary action. If you need further assistance or have any questions, feel free to let me know.'"
241
+ ]
242
+ },
243
+ "execution_count": 78,
244
+ "metadata": {},
245
+ "output_type": "execute_result"
246
+ }
247
+ ],
248
+ "source": [
249
+ "generate_response('where can i see my invoice for a particular order')"
250
+ ]
251
+ },
252
+ {
253
+ "cell_type": "code",
254
+ "execution_count": 41,
255
+ "metadata": {},
256
+ "outputs": [],
257
+ "source": [
258
+ "demo = gr.ChatInterface(\n",
259
+ " fn=generate_response,\n",
260
+ " examples=[\n",
261
+ " \"What Payment Modalities are accepted?\", \n",
262
+ " \"Can you help me cancel an order?\", \n",
263
+ " \"What is your name and how can you help me today?\"\n",
264
+ " ], \n",
265
+ " title=\"Customer Support\"\n",
266
+ " )"
267
+ ]
268
+ },
269
+ {
270
+ "cell_type": "code",
271
+ "execution_count": 44,
272
+ "metadata": {},
273
+ "outputs": [
274
+ {
275
+ "name": "stdout",
276
+ "output_type": "stream",
277
+ "text": [
278
+ "Running on local URL: http://127.0.0.1:7860\n",
279
+ "\n",
280
+ "To create a public link, set `share=True` in `launch()`.\n"
281
+ ]
282
+ },
283
+ {
284
+ "data": {
285
+ "text/html": [
286
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
287
+ ],
288
+ "text/plain": [
289
+ "<IPython.core.display.HTML object>"
290
+ ]
291
+ },
292
+ "metadata": {},
293
+ "output_type": "display_data"
294
+ },
295
+ {
296
+ "data": {
297
+ "text/plain": []
298
+ },
299
+ "execution_count": 44,
300
+ "metadata": {},
301
+ "output_type": "execute_result"
302
+ },
303
+ {
304
+ "name": "stderr",
305
+ "output_type": "stream",
306
+ "text": [
307
+ "Llama.generate: 25 prefix-match hit, remaining 59 prompt tokens to eval\n",
308
+ "llama_perf_context_print: load time = 8944.43 ms\n",
309
+ "llama_perf_context_print: prompt eval time = 0.00 ms / 59 tokens ( 0.00 ms per token, inf tokens per second)\n",
310
+ "llama_perf_context_print: eval time = 0.00 ms / 70 runs ( 0.00 ms per token, inf tokens per second)\n",
311
+ "llama_perf_context_print: total time = 15979.58 ms / 129 tokens\n",
312
+ "Llama.generate: 67 prefix-match hit, remaining 13 prompt tokens to eval\n",
313
+ "llama_perf_context_print: load time = 8944.43 ms\n",
314
+ "llama_perf_context_print: prompt eval time = 0.00 ms / 13 tokens ( 0.00 ms per token, inf tokens per second)\n",
315
+ "llama_perf_context_print: eval time = 0.00 ms / 54 runs ( 0.00 ms per token, inf tokens per second)\n",
316
+ "llama_perf_context_print: total time = 13241.01 ms / 67 tokens\n",
317
+ "Llama.generate: 67 prefix-match hit, remaining 19 prompt tokens to eval\n",
318
+ "llama_perf_context_print: load time = 8944.43 ms\n",
319
+ "llama_perf_context_print: prompt eval time = 0.00 ms / 19 tokens ( 0.00 ms per token, inf tokens per second)\n",
320
+ "llama_perf_context_print: eval time = 0.00 ms / 169 runs ( 0.00 ms per token, inf tokens per second)\n",
321
+ "llama_perf_context_print: total time = 32806.53 ms / 188 tokens\n"
322
+ ]
323
+ }
324
+ ],
325
+ "source": [
326
+ "demo.launch()"
327
+ ]
328
+ },
329
+ {
330
+ "cell_type": "code",
331
+ "execution_count": 62,
332
+ "metadata": {},
333
+ "outputs": [
334
+ {
335
+ "name": "stdout",
336
+ "output_type": "stream",
337
+ "text": [
338
+ "Closing server running on port: 7860\n"
339
+ ]
340
+ }
341
+ ],
342
+ "source": [
343
+ "demo.close()"
344
+ ]
345
+ }
346
+ ],
347
+ "metadata": {
348
+ "kernelspec": {
349
+ "display_name": "Python 3",
350
+ "language": "python",
351
+ "name": "python3"
352
+ },
353
+ "language_info": {
354
+ "codemirror_mode": {
355
+ "name": "ipython",
356
+ "version": 3
357
+ },
358
+ "file_extension": ".py",
359
+ "mimetype": "text/x-python",
360
+ "name": "python",
361
+ "nbconvert_exporter": "python",
362
+ "pygments_lexer": "ipython3",
363
+ "version": "3.10.5"
364
+ }
365
+ },
366
+ "nbformat": 4,
367
+ "nbformat_minor": 2
368
+ }