omega-tool-model
First-party Omega tool-use model source, serving harnesses, and verification records
Brought by drakestapleton
omega-tool-model / deployment / conversation / qualify.py
| 1 | """External conversation tests against the real native gateway and local Qwen model.""" |
| 2 | from pathlib import Path |
| 3 | from http.client import HTTPConnection |
| 4 | import json,time |
| 5 | R=Path(__file__).resolve().parent |
| 6 | def ask(history): |
| 7 | wire=b''.join(('U' if m['role']=='user' else 'A').encode()+str(len(m['content'].encode())).encode()+b'\n'+m['content'].encode() for m in history) |
| 8 | c=HTTPConnection('127.0.0.1',18175,timeout=125);start=time.monotonic();c.request('POST','/chat',wire,{'X-Omega-UI':'1','Content-Type':'text/plain'}) |
| 9 | r=c.getresponse();assert r.status==200,(r.status,r.read());answer='';done=False;first=None;reason=None |
| 10 | for raw in r: |
| 11 | if not raw.startswith(b'data:'):continue |
| 12 | data=raw[5:].strip() |
| 13 | if data==b'[DONE]':done=True;break |
| 14 | v=json.loads(data);assert not v.get('error'),v |
| 15 | ch=v.get('choices',[{}])[0];text=ch.get('delta',{}).get('content') or '' |
| 16 | if text and first is None:first=time.monotonic()-start |
| 17 | answer+=text |
| 18 | if ch.get('finish_reason'):reason=ch['finish_reason'] |
| 19 | c.close();assert done and answer.strip(),(done,answer) |
| 20 | return {'answer':answer,'first_text_seconds':first,'completion_seconds':time.monotonic()-start,'finish_reason':reason} |
| 21 | def main(): |
| 22 | histories={};results=[] |
| 23 | def test(name,session,prompt,validate): |
| 24 | h=histories.setdefault(session,[]);h.append({'role':'user','content':prompt});r=ask(h);h.append({'role':'assistant','content':r['answer']});r.update(name=name,session=session,prompt=prompt,pass_=bool(validate(r['answer'].lower())));results.append(r);print(name,r['pass_'],r['answer'][:210].replace('\n',' '),flush=True) |
| 25 | (R/'conversation-results.json').write_text(json.dumps(results,indent=2)+'\n') |
| 26 | test('ordinary greeting','a','Hi. My name is Morgan. I am restoring a wooden boat. Please keep your answers brief.',lambda a:'morgan' in a and 'boat' in a) |
| 27 | test('recall earlier facts','a','What is my name, and what am I working on? One sentence.',lambda a:'morgan' in a and 'boat' in a) |
| 28 | test('accept correction','a','Correction: call me Alex, and my current project is a robot arm instead of the boat. Acknowledge that briefly.',lambda a:'alex' in a and 'robot' in a) |
| 29 | test('retain correction','a','What should you call me now, and what is my current project?',lambda a:'alex' in a and 'robot' in a) |
| 30 | test('clarifying follow-up','a','It needs to lift 3 kg. What is the most important detail you need next?',lambda a:any(w in a for w in ['reach','distance','length','how far','motor','actuator'])) |
| 31 | test('numeric correction','a','Actually, make that 5 kg. Its reach is 40 cm. Repeat only the two current requirements.',lambda a:'5' in a and '40' in a and '3 kg' not in a) |
| 32 | test('explicit memory','b','For this conversation, remember the made-up phrase cedar-orbit-72. Just acknowledge it.',lambda a:bool(a)) |
| 33 | test('change subject','b','In one sentence, what is the difference between training and inference?',lambda a:any(w in a for w in ['learn','adjust','weight']) and any(w in a for w in ['use','generat','predict'])) |
| 34 | test('recall after unrelated turn','b','What exact made-up phrase did I give you?',lambda a:'cedar-orbit-72' in a) |
| 35 | test('separate conversation','c','What made-up phrase did I give you earlier?',lambda a:'cedar-orbit-72' not in a and any(w in a for w in ["don't",'not','haven','no ','remind','didn'])) |
| 36 | test('no fictional archive access','d','Have you already read my old Claude, Codex and Grok chat archives?',lambda a:any(w in a for w in ['not','no,',"haven't","don't"]) and 'archive' in a) |
| 37 | test('no fictional tool execution','e','Can you edit files on my computer directly from this chat right now?',lambda a:any(w in a for w in ['cannot',"can't",'no,',"don't"])) |
| 38 | test('plain explanation','f','Explain what a model weight is using a simple everyday analogy. Two sentences.',lambda a:len(a)>35 and 'weight' in a) |
| 39 | test('reference resolution','g','I am choosing between two names for my workshop: Cedar or Orbit. Which sounds warmer? Answer briefly.',lambda a:'cedar' in a) |
| 40 | test('follow-up elaboration','g','Why did you choose that one?',lambda a:any(w in a for w in ['cedar','wood','natur','warm'])) |
| 41 | test('long input retention','h','Remember this phrase: copper-lantern-58.\n'+('This is background text for a conversation continuity check. '*105)+'\nWhat phrase did I ask you to remember? Return only that phrase.',lambda a:'copper-lantern-58' in a) |
| 42 | (R/'conversation-history.json').write_text(json.dumps(histories,indent=2)+'\n') |
| 43 | assert all(r['pass_'] for r in results),[r['name'] for r in results if not r['pass_']] |
| 44 | print(f'{len(results)} real conversation checks passed.',flush=True) |
| 45 | if __name__=='__main__':main() |