Compare commits

...

18 Commits

3
.gitignore vendored

@ -9,3 +9,6 @@ target
*/dist
*/node_mobules
*/*.lock
json
*.png
*.jpg

@ -12,6 +12,13 @@ $ ./atr
### build
support : cargo 1.67.1
err : cargo 1.6.8.x
> rejected by a future version of Rust: rustc-serialize v0.3.24
```sh
# install rust
$ sudo pacman -S rust
@ -103,3 +110,47 @@ my_bluesky() {
autoload -Uz add-zsh-hook
add-zsh-hook precmd my_bluesky
```
```sh
$ atr deepl-api "xxx"
# deepl translate [en -> ja]
$ atr tt "test" -l ja
# deepl translate [ja -> en]
$ atr tt "テスト" -l en
$ atr p "deeplで翻訳してポストしています" -e
Translated and posted by deepl
$ atr p "Translated and posted by deepl" -j
deeplで翻訳してポストしています
```
```sh
$ atr openai-api "xxx"
$ atr chat "Lexicon is a schema system used to define RPC methods and record types"
It is used in distributed systems to define the various components, such as clients, servers, and databases, and their interactions. Lexicon is often used to define the data structure for RPC methods and records, and to define the communications protocols between the various components of a distributed system.
```
```sh
# reply
$ atr r "reply post" -c $cid -u $uri
# test : post reply option
$ atr p "[en -> ja] translate and post the english to japanese with deepl" -j --cid $cid --uri $uri
$ atr p "[chatgpt] post by openai chatgpt" -c --cid $cid --uri $uri
```
```sh
# test : bot
$ atr bot
```
### ref
openai : https://github.com/syui/msr/tree/openai
deepl : https://github.com/syui/msr/tree/deepl
at : https://atproto.com/guides/lexicon

@ -0,0 +1,79 @@
#!/bin/zsh
home=/home/syui
name=arch
a=$home/$name
function arch_in(){
mkdir -p $a
sudo pacstrap -c $a base
#sudo echo pts/0 >> $a/etc/securetty
#sudo echo pts/1 >> $a/etc/securetty
sudo rm -rf /var/lib/machines/$name
sudo rm -rf /var/lib/machines/${name}back
sudo mv $a /var/lib/machines/
sudo machinectl clone arch archback
}
function arch_rm(){
sudo machinectl remove $name
}
function arch_up(){
sudo machinectl poweroff $name > /dev/null 2>&1
sleep 5
sudo machinectl terminate $name > /dev/null 2>&1
sleep 5
sudo machinectl start ${name}back
sleep 5
ssh ${name}back pacman -Syu --noconfirm
sleep 5
sudo machinectl poweroff ${name}back
}
function arch_st(){
sudo machinectl start $name
}
function arch_of(){
sudo machinectl poweroff $name
}
function arch_ex(){
sudo machinectl shell $name
$1
poweroff
}
function arch_re(){
sudo machinectl poweroff $name > /dev/null 2>&1
sleep 5
sudo machinectl terminate $name > /dev/null 2>&1
sleep 5
sudo machinectl remove $name
sleep 5
sudo machinectl clone ${name}back $name
sleep 5
sudo machinectl start $name
}
case "$1" in
"update"|"-u")
arch_up
arch_re
echo "machinectl update done"
;;
"reset"|"-r")
arch_re
echo "machinectl reset done"
;;
*)
sudo machinectl start $name
t=`ssh $name "$*"`
if [ -z "$t" ];then
ssh -tt $name "$*"
else
echo "$t"
fi
;;
esac

@ -0,0 +1,44 @@
#!/bin/zsh
dir=${0:a:h}
f=$dir/diffusion_prompt.txt
seed=$RANDOM
sd_prompt_a="masterpiece, high quality, very_high_resolution, large_filesize, full color"
case "$1" in
"--anime"|"-a")
## kawaii girl random prompt
ra=$(($RANDOM % 2 + 1))
rp="beautiful kawaii "`echo "little girl,girl"|cut -d , -f $ra|tr -d ,`
rb=$(($RANDOM % 3 + 1))
rbp="with "`echo "gold,silver,black"|cut -d , -f $rb|tr -d ,`" hair"
rc=$(($RANDOM % 4 + 1))
rcp=`echo "wavy,long,straight,"|cut -d , -f $rc|tr -d ,`
rd=$(($RANDOM % 3 + 1))
rdp="in "`echo "fluttery white onepice,simple white onepice,normal white school uniform"|cut -d , -f $rd|tr -d ,`
sd_prompt_a="$sd_prompt_a, $rp $rdp $rcp $rbp"
echo $sd_prompt_a >! $f
;;
"")
exit
;;
*)
echo $sd_prompt_a $* >! $f
;;
esac
cat $f
q=`cat $f`
rm -rf $dir/png
mkdir -p $dir/png
ssh win Remove-Item -Recurse -Force stable-diffusion/outputs
ssh win Remove-Item -Recurse -Force msbot
ssh win mkdir stable-diffusion/outputs
ssh win mkdir msbot
ssh win "conda activate ldm;cd ./stable-diffusion/;python optimizedSD/optimized_txt2img.py --prompt \"${q}\" --H 512 --W 512 --seed $seed --n_iter 1 --n_samples 1 --ddim_steps 50"
diff_dir=`ssh win ls stable-diffusion/outputs/txt2img-samples -Name|cut -b 1-2`
ssh win "cd stable-diffusion/outputs/txt2img-samples;mv $diff_dir* $diff_dir -Force;mv $diff_dir/*.png ~/msbot/t.png -Force"
ssh win ".\scoop\apps\imagemagick\current\convert.exe msbot/t.png msbot/t.jpg"
scp -r win:msbot/t.jpg $dir/png/t.jpg

@ -0,0 +1,31 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
use crate::Handle;
pub async fn post_request(handle: String) -> String {
let token = token_toml(&"access");
let did = token_toml(&"did");
let url = url(&"update_handle");
println!("DNS txt : _atproto.{}, did={}.", handle, did);
let handle = Handle {
handle: handle.to_string()
};
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&handle)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,50 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
use serde_json::json;
use iso8601_timestamp::Timestamp;
pub async fn post_request(text: String, at: String, udid: String, s: i32, e: i32) -> String {
let token = token_toml(&"access");
let did = token_toml(&"did");
let url = url(&"record_create");
let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
let d = d.to_string();
let post = Some(json!({
"did": did.to_string(),
"collection": col.to_string(),
"record": {
"text": at.to_string() + &" ".to_string() + &text.to_string(),
"createdAt": d.to_string(),
"entities": [
{
"type": "mention".to_string(),
"index": {
"end": e,
"start": s
},
"value": udid.to_string()
}
]
},
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,24 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
//use serde_json::json;
pub async fn get_request(limit: i32) -> String {
let token = token_toml(&"access");
let url = url(&"notify_list");
let client = reqwest::Client::new();
let res = client
.get(url)
.query(&[("limit", limit)])
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,28 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
use serde_json::json;
pub async fn post_request(time: String) -> String {
let token = token_toml(&"access");
let url = url(&"notify_update");
let post = Some(json!({
"seenAt": time.to_string(),
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,40 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
use serde_json::json;
use iso8601_timestamp::Timestamp;
pub async fn post_request(text: String) -> String {
let token = token_toml(&"access");
let did = token_toml(&"did");
let url = url(&"record_create");
let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
let d = d.to_string();
let post = Some(json!({
"did": did.to_string(),
"collection": col.to_string(),
"record": {
"text": text.to_string(),
"createdAt": d.to_string(),
},
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,50 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
use serde_json::json;
use iso8601_timestamp::Timestamp;
pub async fn post_request(text: String, link: String, s: i32, e: i32) -> String {
let token = token_toml(&"access");
let did = token_toml(&"did");
let url = url(&"record_create");
let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
let d = d.to_string();
let post = Some(json!({
"did": did.to_string(),
"collection": col.to_string(),
"record": {
"text": link.to_string() + &" ".to_string() + &text.to_string(),
"createdAt": d.to_string(),
"entities": [
{
"type": "link".to_string(),
"index": {
"end": e,
"start": s
},
"value": link.to_string()
}
]
},
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,22 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
pub async fn get_request(user: String) -> String {
let token = token_toml(&"access");
let url = url(&"profile_get") + &"?actor=" + &user;
let client = reqwest::Client::new();
let res = client
.get(url)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,51 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
use serde_json::json;
use iso8601_timestamp::Timestamp;
pub async fn post_request(text: String, cid: String, uri: String) -> String {
let token = token_toml(&"access");
let did = token_toml(&"did");
let url = url(&"record_create");
//let url = "https://bsky.social/xrpc/com.atproto.repo.createRecord";
let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
let d = d.to_string();
let post = Some(json!({
"did": did.to_string(),
"collection": col.to_string(),
"record": {
"text": text.to_string(),
"createdAt": d.to_string(),
"reply": {
"root": {
"cid": cid.to_string(),
"uri": uri.to_string()
},
"parent": {
"cid": cid.to_string(),
"uri": uri.to_string()
}
}
},
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,85 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
use serde_json::json;
use iso8601_timestamp::Timestamp;
pub async fn post_request(text: String, cid: String, uri: String, mid: String, itype: String) -> String {
let token = token_toml(&"access");
let did = token_toml(&"did");
let url = url(&"record_create");
//let url = "https://bsky.social/xrpc/com.atproto.repo.createRecord";
let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
let d = d.to_string();
//{
// "did": "",
// "collection": "",
// "record": {
// "text": "",
// "createdAt": "",
// "": "",
// "embed": {
// "$type": "app.bsky.embed.images",
// "images": [
// {
// "image": {
// "cid": "",
// "mimeType": ""
// },
// "alt": ""
// }
// ]
// }
// }
//}
let post = Some(json!({
"did": did.to_string(),
"collection": col.to_string(),
"record": {
"text": text.to_string(),
"createdAt": d.to_string(),
"embed": {
"$type": "app.bsky.embed.images",
"images": [
{
"image": {
"cid": mid.to_string(),
"mimeType": itype.to_string()
},
"alt": ""
}
]
},
"reply": {
"root": {
"cid": cid.to_string(),
"uri": uri.to_string()
},
"parent": {
"cid": cid.to_string(),
"uri": uri.to_string()
}
}
},
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -0,0 +1,22 @@
extern crate reqwest;
use crate::token_toml;
use crate::url;
pub async fn get_request() -> String {
let token = token_toml(&"access");
let url = url(&"timeline_get");
let client = reqwest::Client::new();
let res = client
.get(url)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res
}

@ -49,6 +49,34 @@ impl Tokens {
s.try_deserialize()
}
}
// config.data
pub fn cfg(s: &str) -> String {
// cfg.dir
let dir = "/.config/atr";
let mut d = shellexpand::tilde("~").to_string();
d.push_str(&dir);
let file = "/.config/atr/config.toml";
let mut f = shellexpand::tilde("~").to_string();
f.push_str(&file);
//cfg.toml
let s = String::from(s);
let data = Data::new().unwrap();
let data = Data {
host: data.host,
user: data.user,
pass: data.pass,
};
match &*s {
"user" => data.user,
"host" => data.host,
"pass" => data.pass,
"dir" => d,
"file" => f,
_ => s,
}
}
// tokne.file
pub fn token_file(s: &str) -> String {
@ -95,6 +123,7 @@ pub struct BaseUrl {
pub account_create: String,
pub notify_count: String,
pub notify_list: String,
pub notify_update: String,
}
pub fn url(s: &str) -> String {
@ -118,6 +147,7 @@ pub fn url(s: &str) -> String {
update_handle: "com.atproto.handle.update".to_string(),
notify_count: "app.bsky.notification.getCount".to_string(),
notify_list: "app.bsky.notification.list".to_string(),
notify_update: "app.bsky.notification.updateSeen".to_string(),
};
match &*s {
"profile_get" => t.to_string() + &baseurl.profile_get,
@ -131,6 +161,7 @@ pub fn url(s: &str) -> String {
"update_handle" => t.to_string() + &baseurl.update_handle,
"notify_list" => t.to_string() + &baseurl.notify_list,
"notify_count" => t.to_string() + &baseurl.notify_count,
"notify_update" => t.to_string() + &baseurl.notify_update,
_ => s,
}
}
@ -199,6 +230,7 @@ pub struct Feed {
pub struct Post {
pub did: Option<String>,
pub uri: String,
pub cid: String,
pub collection: Option<String>,
pub record: Record,
pub author: Author,
@ -220,9 +252,57 @@ pub struct Handle {
pub handle: String
}
//#[derive(Serialize, Deserialize)]
//pub struct Did {
// pub did: String
//}
#[derive(Serialize, Deserialize)]
pub struct Did {
pub did: String
#[allow(non_snake_case)]
pub struct Profile {
pub did: String,
pub handle: String,
//pub followCount: String,
//pub followersCount: String,
//pub postsCount: String,
//pub creator: String,
//pub indexedAt: String,
//pub avatar: Option<String>,
//pub banner: Option<String>,
//pub displayName: Option<String>,
//pub description: Option<String>,
}
#[derive(Debug, Deserialize)]
#[allow(unused)]
pub struct Deep {
pub api: String,
}
impl Deep {
pub fn new() -> Result<Self, ConfigError> {
let d = shellexpand::tilde("~") + "/.config/atr/deepl.toml";
let s = Config::builder()
.add_source(File::with_name(&d))
.add_source(config::Environment::with_prefix("APP"))
.build()?;
s.try_deserialize()
}
}
impl Open {
pub fn new() -> Result<Self, ConfigError> {
let d = shellexpand::tilde("~") + "/.config/atr/openai.toml";
let s = Config::builder()
.add_source(File::with_name(&d))
.add_source(config::Environment::with_prefix("APP"))
.build()?;
s.try_deserialize()
}
}
#[derive(Debug, Deserialize)]
#[allow(unused)]
pub struct Open {
pub api: String,
}

@ -0,0 +1,34 @@
extern crate reqwest;
use crate::Deeps;
use crate::DeepData;
use reqwest::header::AUTHORIZATION;
use reqwest::header::CONTENT_TYPE;
use std::collections::HashMap;
pub async fn post_request(prompt: String, lang: String) -> String {
let lang = lang.to_string();
let data = Deeps::new().unwrap();
let data = Deeps {
api: data.api,
};
let api = "DeepL-Auth-Key ".to_owned() + &data.api;
let mut params = HashMap::new();
params.insert("text", &prompt);
params.insert("target_lang", &lang);
let client = reqwest::Client::new();
let res = client
.post("https://api-free.deepl.com/v2/translate")
.header(AUTHORIZATION, api)
.header(CONTENT_TYPE, "json")
.form(&params)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
let p: DeepData = serde_json::from_str(&res).unwrap();
let o = &p.translations[0].text;
return o.to_string()
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,45 @@
extern crate reqwest;
use crate::Opens;
use crate::OpenData;
use serde_json::{json};
pub async fn post_request(prompt: String, model: String) -> String {
let data = Opens::new().unwrap();
let data = Opens {
api: data.api,
};
let temperature = 0.7;
let max_tokens = 250;
let top_p = 1;
let frequency_penalty = 0;
let presence_penalty = 0;
let stop = "[\"###\"]";
let post = Some(json!({
"prompt": &prompt.to_string(),
"model": &model.to_string(),
"temperature": temperature,
"max_tokens": max_tokens,
"top_p": top_p,
"frequency_penalty": frequency_penalty,
"presence_penalty": presence_penalty,
"stop": stop,
}));
let client = reqwest::Client::new();
let res = client
.post("https://api.openai.com/v1/completions")
.header("Authorization", "Bearer ".to_owned() + &data.api)
.json(&post)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
let p: OpenData = serde_json::from_str(&res).unwrap();
let o = &p.choices[0].text;
return o.to_string()
}
Loading…
Cancel
Save