Skip to main content

This is a module for MobAI.API.

Project description

ShanHeUniversity

使用方法

使用流程总览

1.申请密钥(apply)

2.新建记录(CreateNewAPI)

3.循环聊天(ChatAPI)


v1.api

申请密钥

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码

from ShanHeuniversity import v1
api = v1.api

api.apply(email='demo@shu.edu')

参数总览

参数名 参数类型 是否必填 默认值 示例
email String sb@xxx.com

新建记录

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码

import sys
import os
from ShanHeuniversity import v1
api = v1.api

function = lambda data: sys.stdout.write(str(data))

api._api_key = os.getenv('MOBAI_API_KEY')
function(
    api.CreateNewAPI(model='MobAI')
)

参数总览

参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
model String 天马行空

循环聊天

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码

import sys
import os
from ShanHeuniversity import v1
api = v1.api

function = lambda data: sys.stdout.write(
    'MobAI:' + data.data.reply + '\n\n'
    if data.state == 'success'
    else 'ERROR:' + data.data.error + '\n\n'
)
ask = input

api._api_key = os.getenv('MOBAI_API_KEY')
while True:
    function(
        api.ChatAPI(
            _id='id',
            password='password',
            question=ask('User:')
        )
    )

参数总览

参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
_id String 0000-0000-0000-0000
password String password-1234
question String Hello!

可参考示例

以下代码可直接运行,但不建议,因为这只是一个最基本的示例。

import sys
from ShanHeuniversity import v1
api = v1.api

ask = input
function = lambda data: sys.stdout.write(
    'MobAI:' + str(data.get('data').get('reply')) + '\n\n'
    if data.get('state') == 'success'
    else 'ERROR:' + data.get('data').get('error') + '\n\n'
)

api.apply(email=ask('Mail:'))

api._api_key = ask('Key:')

ai = api.CreateNewAPI(model=ask('Model:'))

while True:
    function(
        api.ChatAPI(
            _id=ai.data.id,
            password=ai.data.password,
            question=ask('User:')
        )
    )

其他功能

聊天记录

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码
import sys
import os
from ShanHeuniversity import v1
api = v1.api

function = lambda data: sys.stdout.write(str(data))

api._api_key = os.getenv('MOBAI_API_KEY')
function(
    api.RecodesAPI(
        _id='id',
        password='password',
    )
)
参数总览
参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
_id String 0000-0000-0000-0000
password String password-1234

检查AP

A: Account 账号

P: Password 密码

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码
import sys
import os
from ShanHeuniversity import v1
api = v1.api

function = lambda data: sys.stdout.write(str(data))

api._api_key = os.getenv('MOBAI_API_KEY')
function(
    api.check(
        _id='id',
        password='password',
    )
)
参数总览
参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
_id String 0000-0000-0000-0000
password String password-1234

检查账号存在性

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码
import sys
import os
from ShanHeuniversity import v1
api = v1.api

function = lambda data: sys.stdout.write(str(data))

api._api_key = os.getenv('MOBAI_API_KEY')
function(
    api.exist(
        _id='id',
    )
)
参数总览
参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
_id String 0000-0000-0000-0000

v2.api

v2.api与v1.api的不同在于v2支持流式返回, 以及v2更加卓越的性能与返回速度, v2接口采用多线程新建, 立即返回id与password, 并将其余的任务交给其他线程完成.

申请密钥

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码

from ShanHeuniversity import v2
api = v2.api

api.apply(email='demo@shu.edu')

参数总览

参数名 参数类型 是否必填 默认值 示例
email String sb@xxx.com

新建记录

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码

import sys
import os
from ShanHeuniversity import v2
api = v2.api

function = lambda data: sys.stdout.write(str(data))

api._api_key = os.getenv('MOBAI_API_KEY')
function(
    api.CreateNewAPI(model='MobAI')
)

参数总览

参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
model String 天马行空

循环聊天

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码

import sys
import os
from ShanHeuniversity import v2
api = v2.api

function = lambda data: sys.stdout.write(
    'MobAI:'
    if data == 0
    else (
        ''
        if isinstance(data, int)
        else (
            data.data.reply
            if data.data.finish is False
            else (
                '\n\n'
                if data.state == 'success'
                else
                'ERROR:' + data.data.error + '\n\n'
            )
        )
    )
)
ask = input

while True:
    token = 0
    for message in api.ChatAPI(
            _id='id',
            password='password',
            question=ask('User:'),
    ).ask():
        function(token)
        function(message)
        token += 1

参数总览

参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
_id String 0000-0000-0000-0000
password String password-1234
question String Hello!

可参考示例

以下代码可直接运行,但不建议,因为这只是一个最基本的示例。

import sys
from ShanHeuniversity import v2
api = v2.api

ask = input
function = lambda data: sys.stdout.write(
    'MobAI:'
    if data == 0
    else (
        ''
        if isinstance(data, int)
        else (
            data.data.reply
            if data.data.finish is False
            else (
                '\n\n'
                if data.state == 'success'
                else
                'ERROR:' + data.data.error + '\n\n'
            )
        )
    )
)

api.apply(email=ask('Mail:'))

api._api_key = ask('Key:')

ai = api.CreateNewAPI(model=ask('Model:'))

while True:
    token = 0
    for message in api.ChatAPI(
            _id=ai.data.id,
            password=ai.data.password,
            question=ask('User:'),
    ).ask():
        function(token)
        function(message)
        token += 1

其他功能

聊天记录

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码
import sys
import os
from ShanHeuniversity import v2
api = v2.api

function = lambda data: sys.stdout.write(str(data))

api._api_key = os.getenv('MOBAI_API_KEY')
function(
    api.RecodesAPI(
        _id='id',
        password='password',
    )
)
参数总览
参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
_id String 0000-0000-0000-0000
password String password-1234

检查AP

A: Account 账号

P: Password 密码

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码
import sys
import os
from ShanHeuniversity import v2
api = v2.api

function = lambda data: sys.stdout.write(str(data))

api._api_key = os.getenv('MOBAI_API_KEY')
function(
    api.check(
        _id='id',
        password='password',
    )
)
参数总览
参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
_id String 0000-0000-0000-0000
password String password-1234

检查账号存在性

准备工作

1.Python3.*

2.pip install shanheuniversity

示例代码
import sys
import os
from ShanHeuniversity import v2
api = v2.api

function = lambda data: sys.stdout.write(str(data))

api._api_key = os.getenv('MOBAI_API_KEY')
function(
    api.exist(
        _id='id',
    )
)
参数总览
参数名 参数类型 是否必填 默认值 示例
api_key String sk-demo
_id String 0000-0000-0000-0000

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ShanHeUniversity-0.2.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

ShanHeUniversity-0.2.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file ShanHeUniversity-0.2.1.tar.gz.

File metadata

  • Download URL: ShanHeUniversity-0.2.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for ShanHeUniversity-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bc41e2d31b10e55af815941bd6a00d189be5d32e21e19aa98b33a349c0c290b4
MD5 8b3c46cd981f6c6d570dde5c1e6bb729
BLAKE2b-256 e79ac640b476b635a5aca53032940595101a05e64df5205516f27d2d348e3d3d

See more details on using hashes here.

File details

Details for the file ShanHeUniversity-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ShanHeUniversity-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5a8f113bb62a04edf3f9f78ae17e69c677b9c866393a51c1568e643c6435595
MD5 5552ef938e7a034d0107716d8cdc60db
BLAKE2b-256 f1e5874dd1ee9757b4e19e765b9034a0af94902bbc69d0481037fcad2c451108

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page