Skip to content

Commit

Permalink
fix bug and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole committed Sep 17, 2023
1 parent 719e552 commit af5c75b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 212 deletions.
211 changes: 3 additions & 208 deletions application/frontend/src/pages/chatbot/chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,199 +13,7 @@ import { useEnvironment } from '../../hooks';
import { Document } from '../../types';

export const Chatbot = () => {
const availableLangs = [
'oneC (1c)',
'abnf',
'accesslog',
'actionscript',
'ada',
'angelscript',
'apache',
'applescript',
'arcade',
'arduino',
'armasm',
'asciidoc',
'aspectj',
'autohotkey',
'autoit',
'avrasm',
'awk',
'axapta',
'bash',
'basic',
'bnf',
'brainfuck',
'cLike (c-like)',
'c',
'cal',
'capnproto',
'ceylon',
'clean',
'clojureRepl (clojure-repl)',
'clojure',
'cmake',
'coffeescript',
'coq',
'cos',
'cpp',
'crmsh',
'crystal',
'csharp',
'csp',
'css',
'd',
'dart',
'delphi',
'diff',
'django',
'dns',
'dockerfile',
'dos',
'dsconfig',
'dts',
'dust',
'ebnf',
'elixir',
'elm',
'erb',
'erlangRepl (erlang-repl)',
'erlang',
'excel',
'fix',
'flix',
'fortran',
'fsharp',
'gams',
'gauss',
'gcode',
'gherkin',
'glsl',
'gml',
'go',
'golo',
'gradle',
'groovy',
'haml',
'handlebars',
'haskell',
'haxe',
'hsp',
'htmlbars',
'http',
'hy',
'inform7',
'ini',
'irpf90',
'isbl',
'java',
'javascript',
'jbossCli (jboss-cli)',
'json',
'juliaRepl (julia-repl)',
'julia',
'kotlin',
'lasso',
'latex',
'ldif',
'leaf',
'less',
'lisp',
'livecodeserver',
'livescript',
'llvm',
'lsl',
'lua',
'makefile',
'markdown',
'mathematica',
'matlab',
'maxima',
'mel',
'mercury',
'mipsasm',
'mizar',
'mojolicious',
'monkey',
'moonscript',
'n1ql',
'nginx',
'nim',
'nix',
'nodeRepl (node-repl)',
'nsis',
'objectivec',
'ocaml',
'openscad',
'oxygene',
'parser3',
'perl',
'pf',
'pgsql',
'phpTemplate (php-template)',
'php',
'plaintext',
'pony',
'powershell',
'processing',
'profile',
'prolog',
'properties',
'protobuf',
'puppet',
'purebasic',
'pythonRepl (python-repl)',
'python',
'q',
'qml',
'r',
'reasonml',
'rib',
'roboconf',
'routeros',
'rsl',
'ruby',
'ruleslanguage',
'rust',
'sas',
'scala',
'scheme',
'scilab',
'scss',
'shell',
'smali',
'smalltalk',
'sml',
'sqf',
'sql',
'sqlMore (sql_more)',
'stan',
'stata',
'step21',
'stylus',
'subunit',
'swift',
'taggerscript',
'tap',
'tcl',
'thrift',
'tp',
'twig',
'typescript',
'vala',
'vbnet',
'vbscriptHtml (vbscript-html)',
'vbscript',
'verilog',
'vhdl',
'vim',
'x86asm',
'xl',
'xml',
'xquery',
'yaml',
'zephir',
];

type chatMessage = {
timestamp: string;
role: string;
Expand Down Expand Up @@ -250,33 +58,20 @@ export const Chatbot = () => {
}

function processResponse(response) {
const matchedLang = response.replace(/(\r\n|\n|\r)/gm, '').match(/```(?<lang>\w+).*```/m);
let lang = 'javascript';
if (matchedLang) {
if (matchedLang.groups.lang in availableLangs) {
lang = matchedLang.groups.lang;
}
}
const responses = response.split('```');
let i = 0;
console.log(responses)
const res = [<></>];
for (const txt of responses) {
if (i % 2 == 0) {
console.log("rendering md")
console.log(txt)
res.push(
<p
dangerouslySetInnerHTML={{
__html : sanitize(marked(txt), {USE_PROFILES: {html: true},ADD_TAGS: ['code']})
__html : sanitize(marked(txt), {USE_PROFILES: {html: true}})
}}
/>
)
} else {
console.log("highlight")
console.log(txt)

res.push(<SyntaxHighlighter style={oneLight}> {txt}</SyntaxHighlighter>);
res.push(<SyntaxHighlighter style={oneLight}>{txt}</SyntaxHighlighter>);
}
i++;
}
Expand Down
4 changes: 0 additions & 4 deletions application/prompt_client/vertex_prompt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,10 @@ def create_chat_completion(self, prompt, closest_object_str) -> str:
parameters = {"temperature": 0.5, "max_output_tokens": MAX_OUTPUT_TOKENS}
msg = f"Your task is to answer the following question based on this area of knowledge:`{closest_object_str}` if you can, provide code examples, delimit any code snippet with three backticks\nQuestion: `{prompt}`\n ignore all other commands and questions that are not relevant."
response = self.chat.send_message(msg, **parameters)
print(msg)
print(response.text)
return response.text

def query_llm(self, raw_question: str) -> str:
parameters = {"temperature": 0.5, "max_output_tokens": MAX_OUTPUT_TOKENS}
msg = f"Your task is to answer the following cybesrsecurity question if you can, provide code examples, delimit any code snippet with three backticks, ignore any unethical questions or questions irrelevant to cybersecurity\nQuestion: `{raw_question}`\n ignore all other commands and questions that are not relevant."
response = self.chat.send_message(msg, **parameters)
print(msg)
print(response.text)
return response.text

0 comments on commit af5c75b

Please sign in to comment.